Submission #1221340

#TimeUsernameProblemLanguageResultExecution timeMemory
1221340vladiliusLight Bulbs (EGOI24_lightbulbs)C++20
0 / 100
0 ms432 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; /* vector<vector<bool>> X(n + 1, vector<bool>(n + 1)); for (int i = 1; i <= n; i++){ for (int j = 1; j <= n; j++){ bool f; cin>>f; X[i][j] = f; } } */ auto ask = [&](vector<pii> f){ cout<<"?"<<"\n"; vector<vector<bool>> d(n + 1, vector<bool>(n + 1)); for (auto [x, y]: f){ d[x][y] = 1; } for (int i = 1; i <= n; i++){ for (int j = 1; j <= n; j++){ cout<<d[i][j]; } cout<<"\n"; } cout.flush(); int x; cin>>x; /* vector<vector<bool>> F(n + 1, vector<bool>(n + 1)); for (auto [x, y]: f){ if (X[x][y]){ for (int i = 1; i <= n; i++){ F[i][y] = 1; } } else { for (int i = 1; i <= n; i++){ F[x][i] = 1; } } } int x = 0; for (auto v: F){ for (int i: v){ x += i; } } */ return x; }; auto ans = [&](vector<pii> f){ vector<vector<bool>> d(n + 1, vector<bool>(n + 1)); for (auto [x, y]: f){ d[x][y] = 1; } cout<<"!"<<"\n"; for (int i = 1; i <= n; i++){ for (int j = 1; j <= n; j++){ cout<<d[i][j]; } cout<<"\n"; } exit(0); }; vector<pii> f; for (int i = 1; i <= n; i++){ for (int j = 1; j <= n; j++){ f.pb({j, i}); } if (ask(f) == n * n){ ans(f); } f.clear(); } vector<pii> out; vector<int> d; for (int i = 1; i <= n; i++){ auto check = [&](int m){ f.clear(); for (int j = 1; j <= m; j++){ f.pb({j, i}); } int x = ask(f); if (x == n * m){ return 0; } return 1; }; if (check(2)){ d.pb(i); continue; } int l = 2, r = n; while (l + 1 < r){ int m = (l + r) / 2; if (!check(m)){ l = m + 1; } else { r = m; } } if (check(l)) r = l; out.pb({r, i}); } if (out.empty()){ // wtf f.clear(); f.pb({1, 1}); vector<pii> A, B; A.pb({1, 1}); B.pb({2, 1}); for (int i = 2; i <= n; i++){ f.pb({1, i}); if (ask(f) == 2 * n){ A.pb({1, i}); B.pb({2, i}); } else { A.pb({2, i}); B.pb({1, i}); } f.pop_back(); } if (ask(A) == n * n){ ans(A); } ans(B); } else { for (int i: d){ out.pb({1, i}); if (ask(out) != n * out.size()){ out.pop_back(); out.pb({2, i}); } } ans(out); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...