# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1058719 | Mr_Husanboy | Light Bulbs (EGOI24_lightbulbs) | C++17 | 1 ms | 456 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.
//#pragma GCC optimize("Ofast,O3")
//#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debugger.cpp"
#else
#define debug(...)
#endif
template<class T>
int len(T &a){
return a.size();
}
using ll = long long;
using pii = pair<int,int>;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
string fileio = "";
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll infl = 1e18;
const int maxn = 1e5 + 1;
int n;
void yesno(bool ok){
cout << (ok ? "Yes\n" : "No\n");
}
int ask(vector<string> &v){
cout << "?" << endl;
for(int i = 0; i < n; i ++){
cout << v[i] << endl;
}
int res; cin >> res;
return res;
}
void out(vector<string> &v){
cout << "!" << endl;
for(int i = 0; i < n; i ++){
cout << v[i] << endl;
}
}
void solve(){
cin >> n;
vector<string> v(n, string(n, '0'));
for(int i = 0; i < n; i++){
v[i] = string(n, '1');
if(ask(v) == n * n){
out(v); return;
}
v[i] = string(n, '0');
}
auto res = v;
int l = 0, r = n - 1;
int last = 0;
while(r - l > 1){
int m = (l + r) / 2;
for(int i = 0; i <= m; i ++) v[0][i] = '1';
last = ask(v);
for(int i = 0; i <= m; i ++) v[0][i] = '0';
if(last == n){
r = 0;
break;
}
if(last == (m + 1) * n){
l = m;
}else r = m;
}
int f = 0;
if(r == 1){
v[0][2] = '1';
v[0][1] = '1';
int cnt = ask(v);
if(cnt == n){
f = 1;
}else if(cnt == n + n){
f = 0;
}else{
v[0][1] = '0';
v[0][0] = '1';
if(ask(v) == n){
f = 0;
}else f = 1;
}
}
v[0][0] = v[0][1] = v[0][2] = '0';
res[0][f] = '1';
for(int i = 1; i < n; i ++){
l = 0, r = n - 1;
while(r - l > 1){
int m = (l + r) / 2;
for(int j = 0; j <= m; j ++) v[i][j] = '1';
int cnt = ask(v);
for(int j = 0; j <= m; j ++) v[i][j] = '0';
if(cnt == n){
r = 0; break;
}
if(cnt == (m + 1) * n){
l = m;
}else r = m;
for(int j = 0; j <= m; j ++) v[i][j] = '0';
}
if(r == 1){
v[0][f] = '1';
v[i][r] = '1';
if(ask(v) != 2 * n){
r = 0;
}
v[0][f] = '0';
v[i][1] = '0';
}
res[i][r] = '1';
}
out(res);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
auto start = chrono::high_resolution_clock::now();
#ifndef LOCAL
if(fileio.size()){
freopen((fileio + ".in").c_str(), "r", stdin);
freopen((fileio + ".out").c_str(), "w", stdout);
}
#endif
int testcases = 1;
#ifdef Tests
cin >> testcases;
#endif
while(testcases --){
solve();
if(testcases) cout << '\n';
#ifdef LOCAL
else cout << '\n';
cout << "_________________________" << endl;
#endif
}
#ifdef LOCAL
auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
#endif
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |