답안 #1058729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058729 2024-08-14T13:03:04 Z Mr_Husanboy Light Bulbs (EGOI24_lightbulbs) C++17
60.6344 / 100
29 ms 936 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;

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

Main.cpp: In function 'int main()':
Main.cpp:207:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
  207 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
Main.cpp:210:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  210 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:211:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  211 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 596 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 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 1 ms 596 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 1 ms 596 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 340 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Partially correct 5 ms 484 KB Partially correct
60 Correct 0 ms 344 KB Output is correct
61 Partially correct 17 ms 692 KB Partially correct
62 Partially correct 22 ms 652 KB Partially correct
63 Partially correct 22 ms 484 KB Partially correct
64 Partially correct 19 ms 484 KB Partially correct
65 Partially correct 19 ms 484 KB Partially correct
66 Partially correct 26 ms 488 KB Partially correct
67 Partially correct 20 ms 888 KB Partially correct
68 Partially correct 19 ms 484 KB Partially correct
69 Partially correct 20 ms 608 KB Partially correct
70 Partially correct 25 ms 664 KB Partially correct
71 Partially correct 19 ms 484 KB Partially correct
72 Correct 0 ms 344 KB Output is correct
73 Correct 1 ms 472 KB Output is correct
74 Correct 2 ms 472 KB Output is correct
75 Partially correct 22 ms 880 KB Partially correct
76 Partially correct 17 ms 480 KB Partially correct
77 Partially correct 17 ms 480 KB Partially correct
78 Correct 1 ms 344 KB Output is correct
79 Partially correct 19 ms 484 KB Partially correct
80 Partially correct 5 ms 488 KB Partially correct
81 Partially correct 22 ms 740 KB Partially correct
82 Partially correct 28 ms 608 KB Partially correct
83 Partially correct 19 ms 480 KB Partially correct
84 Partially correct 18 ms 484 KB Partially correct
85 Partially correct 17 ms 640 KB Partially correct
86 Partially correct 8 ms 480 KB Partially correct
87 Partially correct 20 ms 480 KB Partially correct
88 Partially correct 9 ms 560 KB Partially correct
89 Partially correct 22 ms 708 KB Partially correct
90 Partially correct 12 ms 484 KB Partially correct
91 Partially correct 6 ms 480 KB Partially correct
92 Partially correct 29 ms 688 KB Partially correct
93 Partially correct 15 ms 576 KB Partially correct
94 Partially correct 23 ms 936 KB Partially correct
95 Partially correct 17 ms 524 KB Partially correct
96 Partially correct 18 ms 488 KB Partially correct
97 Correct 1 ms 344 KB Output is correct