# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1058729 | Mr_Husanboy | Light Bulbs (EGOI24_lightbulbs) | C++17 | 29 ms | 936 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;
vector<string> lights;
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 = 0;
#ifndef LOCAL
cin >> res;
#else
vector<vector<int>> on(n, vector<int> (n));
for(int i = 0; i < n; i ++){
for(int j = 0; j < n; j ++){
if(v[i][j] == '1'){
if(lights[i][j] == '1'){
for(int k = 0; k < n; k ++){
on[k][j] = 1;
}
}else{
for(int k = 0; k < n; k ++){
on[i][k] = 1;
}
}
}
}
}
for(int i = 0; i < n; i ++){
for(int j = 0; j < n; j ++){
res += on[i][j];
}
}
#endif
return res;
}
void out(vector<string> &v){
cout << "!" << endl;
for(int i = 0; i < n; i ++){
cout << v[i] << endl;
}
#ifdef LOCAL
int ons = 0;
int cnt = 0;
vector<vector<int>> on(n, vector<int> (n));
for(int i = 0; i < n; i ++){
for(int j = 0; j < n; j ++){
if(v[i][j] == '1'){
if(lights[i][j] == '1'){
for(int k = 0; k < n; k ++){
on[k][j] = 1;
}
}else{
for(int k = 0; k < n; k ++){
on[i][k] = 1;
}
}
ons ++;
}
}
}
for(int i = 0; i < n; i ++){
for(int j = 0; j < n; j ++){
cnt += on[i][j];
}
}
assert(ons == n);
if(cnt != n * n){
cout << "WA" << endl;
for(int i = 0; i < n; i ++){
cout << lights[i] << endl;
}
assert(0);
}else{
cout << "OK" << endl;
}
#endif
}
void solve(){
cin >> n;
#ifdef LOCAL
lights.resize(n);
for(int i = 0; i < n; i ++){
lights[i] = "";
for(int j = 0; j < n; j ++){
//lights[i] += rng() % 2 + '0';
}
cin >> lights[i];
}
#endif
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 = r;
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... |