Submission #1357248

#TimeUsernameProblemLanguageResultExecution timeMemory
1357248mxhrvsLight Bulbs (EGOI24_lightbulbs)C++20
0 / 100
0 ms436 KiB
#include <bits/stdc++.h>
using namespace std;

int query(int n, const vector<string>& s) {
    cout << "?\n";
    for(int i = 0; i < n; i++) cout << s[i] << endl;
    int x;
    cin >> x;
    return x;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    vector<string> s(n, string(n, '0'));
    vector<int> result_h(n, -1);

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) s[i][j] = '1';
        int x = query(n, s);
        if(x == n * n) {
            cout << "!\n";
            for(int j = 0; j < n; j++) cout << s[j] << endl;
            return 0;
        }
        for(int j = 0; j < n; j++) s[i][j] = '0'; 

        int low = 0, high = n - 1;
        while(low < high) {
            int mid = low + (high - low) / 2;
            for(int j = low; j <= mid; j++) s[i][j] = '1';
            
            int res = query(n, s);
            int num_lamps = (mid - low + 1);
            
            for(int j = low; j <= mid; j++) s[i][j] = '0'; 

            if(res < num_lamps * n) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }
        result_h[i] = low;
    }


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

    cout << "!\n";
    for(int i = 0; i < n; i++) cout << s[i] << endl;

    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...