Submission #839632

#TimeUsernameProblemLanguageResultExecution timeMemory
839632sleepntsheepCombo (IOI18_combo)C++17
0 / 100
0 ms284 KiB
#include "combo.h" #include <cassert> #include <string> #include <vector> using namespace std; string guess_sequence(int N) { string ans(2, 0); int j = 0, fst = -1, C = 0; vector<int> non(N+5, 0); for (int i = 0; i < 4; ++i) { if (i == 3) ans[0] = 'Y', ++j; else { ans[0] = "ABXY"[i]; ans[1] = i ? 'A': 'B'; int k = press(ans); ++C; if (k == 1) ++j, non[1] |= (i ? 1 : 2); if (k == 2) j += 2; if (k >= 1) { fst = i; break; } } } /* 3 + (N-2) * 2 + 2 = 5 + 2 N - 4 = 2 N + 1 */ for (int j = 1; j < N; ++j) non[j] |= (1 << fst); for (int i = j; i < N - 1;) { int nxt = i + 1; for (int j = 0; j < 4; j++) { if (non[i] & (1 << j)) continue; if (j == 3) ans[i] = 'Y'; else { ans.resize(i+2); ans[i] = "ABXY"[j]; ans[i+1] = 'A'; int k = press(ans); ++C; if (k == i + 1) non[i+1] |= 1; if (k == i + 2) nxt = i + 2; if (k >= i + 1) break; } } i = nxt; } ans.resize(N); for (int j = 0; j < 4; j++) { if (non[N-1] & (1 << j)) continue; if (j == 3) ans[N-1] = 'Y'; else { ans[N-1] = "ABXY"[j]; int k = press(ans); ++C; if (k == N) break; } } if (N > 3) assert(max(N+10,2*N+1)>=C); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...