Submission #1053726

#TimeUsernameProblemLanguageResultExecution timeMemory
1053726LudisseyLight 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 << endl; } cout.flush(); // Ensure the output is flushed immediately } int find_next(int l, int r){ int c = 0; if(l == 0){ c++; if(r == 1) c++; } return c; } signed main() { // Ignore SIGPIPE to prevent crashing when the pipe is closed signal(SIGPIPE, SIG_IGN); ios_base::sync_with_stdio(false); cin.tie(nullptr); 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 << "?" << endl; output(); for (int j = 0; j < N; j++) grid[i][j] = 0; int base; cin >> base; if (base == N*N) { cout << "!" << endl; for (int j = 0; j < N; j++) grid[i][j] = 1; output(); 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 << "?" << endl; output(); for (int j = 0; j < N; j++) grid[i][j] = 0; 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 << "?" << endl; output(); 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 << "?" << endl; output(); cin >> res; if (res == N*2 - 1) { grid[i][r] = 0; cout << "?" << endl; output(); cin >> res; if (res == N*2 - 1) pos[i] = r; else pos[i] = l; } else { grid[i][r] = 0; cout << "?" << endl; output(); 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 << "!" << endl; output(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...