# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1058581 | Zbyszek99 | Light Bulbs (EGOI24_lightbulbs) | C++17 | 62 ms | 600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define size(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace std;
//mt19937 mt;void random(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll rand(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
int n;
int type[102][102];
int rep_[102][2][2];
bool was_[102][2];
int ask(vector<pii> v)
{
string q = "?\n";
set<pii> s;
forall(it,v) s.insert(it);
rep(i,n)
{
rep(j,n)
{
if(s.find({i,j}) == s.end())
{
q += '0';
}
else
{
q += '1';
}
}
q += '\n';
}
cout << q;
cout.flush();
int ans;
cin >> ans;
cout.flush();
return ans;
}
void solve()
{
cin >> n;
cout.flush();
type[0][0] = 0;
rep(i,n)
{
rep_[i][0][0] = -1;
rep_[i][0][1] = -1;
rep_[i][1][0] = -1;
rep_[i][1][1] = -1;
}
rep(i,n)
{
if(i%2 == 0)
{
rep(j,n-1)
{
int ans = ask({{i,j},{i,j+1}});
if(ans == n || ans == n*2)
{
type[i][j+1] = type[i][j];
}
else
{
type[i][j+1] = type[i][j] ^ 1;
}
}
if(i != n-1)
{
int ans = ask({{i,n-1},{i+1,n-1}});
if(ans == n || ans == n*2)
{
type[i+1][n-1] = type[i][n-1];
}
else
{
type[i+1][n-1] = type[i][n-1] ^ 1;
}
}
}
else
{
for(int j = n-1; j >= 1; j--)
{
int ans = ask({{i,j},{i,j-1}});
if(ans == n || ans == n*2)
{
type[i][j-1] = type[i][j];
}
else
{
type[i][j-1] = type[i][j] ^ 1;
}
}
if(i != n-1)
{
int ans = ask({{i,0},{i+1,0}});
if(ans == n || ans == 2*n)
{
type[i+1][0] = type[i][0];
}
else
{
type[i+1][0] = type[i][0] ^ 1;
}
}
}
}
bool was = false;
rep(i,n)
{
rep(j,n)
{
if(rep_[i][1][type[i][j]] != -1)
{
was = true;
if(ask({{i,rep_[i][1][type[i][j]]},{i,j}}) == n)
{
if(type[i][j] == 1)
{
rep(k,n)
{
rep(u,n)
{
type[k][u] ^= 1;
}
}
}
}
else
{
if(type[i][j] == 0)
{
rep(k,n)
{
rep(u,n)
{
type[k][u] ^= 1;
}
}
}
}
break;
}
if(rep_[j][0][type[i][j]] != -1)
{
was = true;
if(ask({{rep_[i][1][type[i][j]],j},{i,j}}) == n)
{
if(type[i][j] == 0)
{
rep(k,n)
{
rep(u,n)
{
type[k][u] ^= 1;
}
}
}
}
else
{
if(type[i][j] == 1)
{
rep(k,n)
{
rep(u,n)
{
type[k][u] ^= 1;
}
}
}
}
break;
}
rep_[i][1][type[i][j]] = j;
rep_[j][0][type[i][j]] = i;
}
if(was) break;
}
// cout << "type\n";
// rep(i,n)
// {
// rep(j,n)
// {
// cout << type[i][j];
// }
// cout << "\n";
// }
// cout << "type\n";
cout << "!\n";
int sum0 = 0;
int sum1 = 0;
rep(i,n)
{
rep(j,n)
{
if(type[i][j] == 1)
{
if(!was_[j][1]) sum1++;
was_[j][1] = true;
}
else
{
if(!was_[i][0]) sum0++;
was_[i][0] = true;
}
}
}
rep(i,n)
{
was_[i][0] = false;
was_[i][1] = false;
}
// cout << sum0 << " " << sum1 << " sum\n";
if(sum1 == n)
{
rep(i,n)
{
rep(j,n)
{
if(type[i][j] == 1)
{
if(!was_[j][0]) cout << "1";
else cout << "0";
was_[j][0] = true;
}
else
{
cout << "0";
}
}
cout << "\n";
}
cout.flush();
}
else if(sum0 == n)
{
rep(i,n)
{
rep(j,n)
{
if(type[i][j] == 0)
{
if(!was_[i][1]) cout << "1";
else cout << "0";
was_[i][1] = true;
}
else
{
cout << "0";
}
}
cout << "\n";
}
cout.flush();
}
else cout << "xd\n";
}
int main()
{
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//random();
int t = 1;
// cin >> t;
while(t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |