Created
May 4, 2019 13:42
-
-
Save qnighy/3129cf09a02c4990aad005a7f71b3b8d to your computer and use it in GitHub Desktop.
GCJ2019 Qual
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
int T; scanf("%d", &T); | |
for(int tci = 0; tci < T; ++tci) { | |
static char b[200]; | |
size_t b_len = 0; | |
scanf(" "); | |
printf("Case #%d: ", tci + 1); | |
while(true) { | |
char n_digit_ch; scanf("%c", &n_digit_ch); | |
if(!('0' <= n_digit_ch && n_digit_ch <= '9')) break; | |
int n_digit = n_digit_ch - '0'; | |
int b_digit = n_digit / 2; | |
if(n_digit >= 7) --b_digit; | |
int a_digit = n_digit - b_digit; | |
printf("%c", a_digit + '0'); | |
if(b_len > 0 || b_digit > 0) { | |
b[b_len++] = b_digit + '0'; | |
} | |
} | |
b[b_len++] = '\0'; | |
printf(" %s\n", b); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
int T; scanf("%d", &T); | |
for(int tci = 0; tci < T; ++tci) { | |
int N; scanf("%d ", &N); | |
printf("Case #%d: ", tci + 1); | |
for(int i = 0; i < 2 * N - 2; ++i) { | |
fputc('E' ^ 'S' ^ fgetc(stdin), stdout); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
面倒なのでやってない |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
static int N, B, F; | |
void ask(int bits[]); | |
void solve(int answer[]) { | |
int bits[1024]; | |
int ok_count[1024]; | |
{ | |
for(int i = 0; i < N; ++i) bits[i] = (i / 16) & 1; | |
ask(bits); | |
int functioning = 0; | |
int bucket_id = 0; | |
for(int i = 0; i < N - B; ++i) { | |
++functioning; | |
if(i == N - B - 1 || bits[i] != bits[i + 1]) { | |
ok_count[bucket_id] = functioning; | |
bucket_id++; | |
functioning = 0; | |
} | |
} | |
} | |
for(int bsize = 8; bsize > 0; bsize /= 2) { | |
int ok_count_old[1024]; | |
for(int i = 0; i < (N + bsize * 2 - 1) / (bsize * 2); ++i) ok_count_old[i] = ok_count[i]; | |
for(int i = 0; i < N; ++i) bits[i] = (i / bsize) & 1; | |
ask(bits); | |
int j = 0; | |
for(int i = 0; i < (N + bsize * 2 - 1) / (bsize * 2); ++i) { | |
int cts[2] = {}; | |
for(int k = 0; k < ok_count_old[i]; ++k) { | |
cts[bits[j++]]++; | |
} | |
// fprintf(stderr, " ok_count[%d] = %d\n", i * 2, cts[0]); | |
// fprintf(stderr, " ok_count[%d] = %d\n", i * 2 + 1, cts[1]); | |
ok_count[i * 2] = cts[0]; | |
ok_count[i * 2 + 1] = cts[1]; | |
} | |
} | |
{ | |
int k = 0; | |
for(int i = 0; i < N; ++i) { | |
if(ok_count[i] == 0) { | |
answer[k++] = i; | |
} | |
} | |
} | |
} | |
void ask(int bits[]) { | |
// { | |
// fprintf(stderr, " ask(["); | |
// for(int i = 0; i < N; ++i) { | |
// fprintf(stderr, "%d, ", bits[i]); | |
// } | |
// fprintf(stderr, "])\n"); | |
// } | |
for(int i = 0; i < N; ++i) { | |
printf("%d", bits[i] & 1); | |
} | |
printf("\n"); | |
fflush(stdout); | |
char resp[1050]; scanf(" %1049s", resp); | |
if(!strcmp(resp, "-1")) exit(0); | |
// { | |
// fprintf(stderr, " ask -> ["); | |
// for(int i = 0; i < N - B; ++i) { | |
// fprintf(stderr, "%c, ", resp[i]); | |
// } | |
// fprintf(stderr, "]\n"); | |
// } | |
for(int i = 0; i < N - B; ++i) { | |
bits[i] = (resp[i] - '0') & 1; | |
} | |
} | |
int main() { | |
int T; scanf("%d", &T); | |
for(int tci = 0; tci < T; ++tci) { | |
scanf("%d%d%d", &N, &B, &F); | |
int answer[15]; | |
// fprintf(stderr, "solve(%d, %d, %d)\n", N, B, F); | |
solve(answer); | |
for(int i = 0; i < B; ++i) { | |
printf("%d%c", answer[i], " \n"[i + 1 == B]); | |
} | |
fflush(stdout); | |
// { | |
// fprintf(stderr, "solve -> ["); | |
// for(int i = 0; i < B; ++i) { | |
// fprintf(stderr, "%d, ", answer[i]); | |
// } | |
// fprintf(stderr, "]\n"); | |
// } | |
int resp; scanf(" %d", &resp); | |
if(resp == -1) exit(0); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/make -f | |
EXECS = a b d | |
CXX = g++ | |
CXXFLAGS = -O2 -Wall -Wextra -g -std=gnu++14 | |
all: $(EXECS) | |
clean: | |
$(RM) $(EXECS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment