답안 #1058719

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058719 2024-08-14T12:49:42 Z Mr_Husanboy Light Bulbs (EGOI24_lightbulbs) C++17
0 / 100
1 ms 456 KB
//#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

Main.cpp: In function 'int main()':
Main.cpp:137:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
  137 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
Main.cpp:140:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  140 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:141:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  141 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Incorrect 0 ms 344 KB The lamps do not light up the entire grid
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Incorrect 0 ms 344 KB The lamps do not light up the entire grid
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Incorrect 0 ms 344 KB The lamps do not light up the entire grid
13 Halted 0 ms 0 KB -