Last active
April 7, 2019 05:01
-
-
Save spdskatr/f59a22cbbdd3adc3b3a2b567f6c11900 to your computer and use it in GitHub Desktop.
GCJ 2019 Qualifier Problem 4 "Dat Bae" solution with F = 4
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 <cstdio> | |
#include <cstdlib> | |
#include <cassert> | |
#include <cstring> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
int T, a[1024], tc[4][1024], tb[1024]; | |
void take_inp(int nb, int *buf) { | |
for (int i = 0; i < nb; i++) { | |
buf[i] = getchar() - '0'; | |
assert(buf[i] == 1 || buf[i] == 0); | |
} getchar(); | |
} | |
void do_test(int b, int N, int B) { | |
for (int i = 0; i < N; i++) { | |
printf("%d", (i & (1<<b)) >> b); | |
} printf("\n"); fflush(stdout); | |
take_inp(N-B, tc[b]); | |
} | |
int main() { | |
scanf("%d", &T); | |
for (int t = 0; t < T; t++) { | |
int N, B, F; | |
// Clear globals | |
memset(tc, 0, sizeof(tc)); | |
memset(tb, 0, sizeof(tb)); | |
// Read in input | |
scanf("%d %d %d", &N, &B, &F); getchar(); | |
for (int i = 0; i < 4; i++) do_test(i, N, B); | |
// Build integers | |
for (int i = 0; i < 4; i++) for (int j = 0; j < N-B; j++) tb[j] |= (tc[i][j] << i); | |
// Figure out where there are gaps | |
int pp = 0, cv = 0, fi = 0; | |
for (int i = 0; i < N-B+1; i++) { | |
if (i > 0 && tb[i] <= tb[i-1]) cv += 16; | |
cv += tb[i]; | |
if (i > 0) cv -= tb[i-1]; | |
while (pp < cv && pp < N) { | |
if (!(fi++)) printf("%d", pp++); | |
else printf(" %d", pp++); | |
} | |
pp++; | |
} printf("\n"); | |
fflush(stdout); | |
int res; scanf("%d", &res); if (res != 1) break; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment