제출 #1364896

#제출 시각아이디문제언어결과실행 시간메모리
1364896biserailievaLight Bulbs (EGOI24_lightbulbs)C++20
0 / 100
0 ms444 KiB
#include <bits/stdc++.h>
using namespace std;

int n;

int askRow(int row, int l, int r){
    cout << "?" << endl;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == row && j >= l && j <= r) cout << 1;
            else cout << 0;
        }
        cout << endl;
    }

    cout.flush();

    int x;
    cin >> x;
    return x;
}

bool hasH(int row, int l, int r){
    int k = r - l + 1;
    int val = askRow(row, l, r);

    return val != k * n; 
}

int findH(int row){
    int l = 0, r = n - 1;
    int pos = -1;

    while(l <= r){
        int mid = (l + r) / 2;

        if(hasH(row, 0, mid)){
            pos = mid;
            r = mid - 1;
        }
        else{
            l = mid + 1;
        }
    }

    return pos;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);

    cin >> n;

    vector<vector<int>> ans(n, vector<int>(n, 0));

    vector<pair<int,int>> chosen;

    for(int i = 0; i < n; i++){

        if(!hasH(i, 0, n-1)){

            for(int j = 0; j < n; j++){
                ans[i][j] = 1;
            }

            cout << "!" << endl;
            for(int x = 0; x < n; x++){
                for(int y = 0; y < n; y++){
                    cout << ans[x][y];
                }
                cout << endl;
            }
            cout.flush();
            return 0;
        }

        int pos = findH(i);
        chosen.push_back({i, pos});
    }

    for(auto [x, y] : chosen){
        ans[x][y] = 1;
    }

    cout << "!" << endl;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cout << ans[i][j];
        }
        cout << endl;
    }

    cout.flush();

    return 0;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…