Submission #1053739

#TimeUsernameProblemLanguageResultExecution timeMemory
1053739LudisseyLight Bulbs (EGOI24_lightbulbs)C++17
0 / 100
0 ms344 KiB
#include <bits/stdc++.h> #include <signal.h> #define int long long #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() using namespace std; int N, M, Q; vector<vector<int>> grid; void output(){ for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cout << grid[i][j] << " "; } cout << "\n"; } } int find_next(int l, int r){ int c = 0; if(l == 0){ c++; if(r == 1) c++; } return c; } signed main() { cin >> N; vector<int> pos(N); grid.resize(N, vector<int>(N, 0)); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) grid[i][j] = 1; cout << "?" << "\n"; output(); cout << flush; for (int j = 0; j < N; j++) grid[i][j] = 0; int base; cin >> base; if (base == N*N) { cout << "!" << "\n"; for (int j = 0; j < N; j++) grid[i][j] = 1; output(); cout << flush; return 0; } int l = 0, r = N-1; while (r - l > 1) { int mid = (l + r) / 2; for (int j = l; j <= mid; j++) grid[i][j] = 1; cout << "?" << "\n"; output(); for (int j = 0; j < N; j++) grid[i][j] = 0; cout << flush; int res; cin >> res; if (res < (mid - l + 1) * N) { r = mid; } else { l = mid + 1; } } int rnd = find_next(l, r); if (l == r) { pos[i] = l; continue; } grid[i][l] = 1; grid[i][r] = 1; cout << "?" << "\n"; output(); cout << flush; int res; cin >> res; if (res == N) { grid[i][l] = 0; grid[i][r] = 0; pos[i] = l; continue; } if (res == 2*N) { grid[i][l] = 0; grid[i][r] = 0; pos[i] = r+1; continue; } grid[i][rnd] = 1; cout << "?" << "\n"; output(); cout << flush; cin >> res; if (res == N*2 - 1) { grid[i][r] = 0; cout << "?" << "\n"; output(); cout << flush; cin >> res; if (res == N*2 - 1) pos[i] = r; else pos[i] = l; } else { grid[i][r] = 0; cout << "?" << "\n"; output(); cout << flush; cin >> res; if (res == N*2 - 1) pos[i] = l; else pos[i] = r; } grid[i][rnd] = 0; grid[i][l] = 0; } for (int i = 0; i < N; i++) { grid[i][pos[i]] = 1; } cout << "!" << "\n"; output(); cout << flush; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...