Submission #1222859

#TimeUsernameProblemLanguageResultExecution timeMemory
1222859overwatch9Light Bulbs (EGOI24_lightbulbs)C++20
22 / 100
77 ms476 KiB
#include <bits/stdc++.h>
using namespace std;
vector <string> actual, ans, query;
int n;
void print_query() {
    cout << "?" << endl;
    for (int i = 0; i < n; i++)
        cout << query[i] << endl;
}
int get_random(int l, int r) {
    return l + rand() % (r - l + 1);
}
void eras(set <int> &s, int x) {
    if (s.find(x) != s.end())
        s.erase(x);
}
void print_ans(char x) {
    cout << "!" << endl;
    if (x == 'V') {
        for (int j = 0; j < n; j++) {
            for (int i = 0; i < n; i++) {
                if (actual[i][j] == 'V') {
                    ans[i][j] = '1';
                    break;
                }
            }
        }
    } else {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (actual[i][j] == 'H') {
                    ans[i][j] = '1';
                    break;
                }
            }
        }
    }

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

}
int main() {
    cin >> n;
    actual = ans = query = vector <string> (n);
    set <int> rows, columns;
    int res;
    for (int i = 0; i < n; i++) {
        actual[i].resize(n, '0');
        ans[i].resize(n, '0');
        query[i].resize(n, '0');
        rows.insert(i);
        columns.insert(i);
    }

    query[0][0] = '1';
    query[n-1][0] = '1';
    print_query();
    query[0][0] = '0';
    query[n-1][0] = '0';
    int cur;
    cin >> cur;
    if (cur == n) {
        // both vertical
        actual[0][0] = actual[n-1][0] = 'V';
        eras(columns, 0);
    } else if (cur == n * 2) {
        // both horizontal
        actual[0][0] = actual[n-1][0] = 'H';
        eras(rows, 0);
        eras(rows, n-1);
    }

    if (actual[0][0] == 'H') {
        for (int i = 1; i < n-1; i++) {
            query[0][0] = query[i][0] = '1';
            print_query();
            query[0][0] = query[i][0] = '0';
            int res;
            cin >> res;
            if (res == 2 * n) {
                actual[i][0] = 'H';
                eras(rows, i);
            }
            else {
                actual[i][0] = 'V';
                eras(columns, 0);
            }
        }
    } else if (actual[0][0] == 'V') {
        for (int i = 1; i < n-1; i++) {
            query[0][0] = query[i][0] = '1';
            print_query();
            query[0][0] = query[i][0] = '0';
            int res;
            cin >> res;
            if (res == n) {
                actual[i][0] = 'V';
                eras(columns, 0);
            }
            else {
                actual[i][0] = 'H';
                eras(rows, i);
            }
        }
    } else {
        
        for (int i = 1; i < n-1; i++) {
            query[0][0] = query[n-1][0] = query[i][0] = '1';
            print_query();
            query[0][0] = query[n-1][0] = query[i][0] = '0';
            int res;
            cin >> res;
            if (res > cur) {
                actual[i][0] = 'H';
                eras(rows, i);
            }
            else {
                actual[i][0] = 'V';
                eras(columns, 0);
            }
        }
    }
    
    if (actual[0][0] == '0') {
        query[0][0] = query[1][0] = '1';
        print_query();
        query[0][0] = query[1][0] = '0';
        cin >> cur;
        if (actual[1][0] == 'H') {
            if (cur == 2 * n) {
                actual[0][0] = 'H';
                actual[n-1][0] = 'V';
                eras(rows, 0);
                eras(columns, 0);
            } else {
                actual[0][0] = 'V';
                actual[n-1][0] = 'H';
                eras(columns, 0);
                eras(rows, n-1);
            }
        } else {
            if (cur == n) {
                actual[0][0] = 'V';
                actual[n-1][0] = 'H';
                eras(columns, 0);
                eras(rows, n-1);
            } else {
                actual[0][0] = 'H';
                actual[n-1][0] = 'V';
                eras(rows, 0);
                eras(columns, 0);
            }
        }
    }


    while (!rows.empty() && !columns.empty()) {
        int x = get_random(0, n-1);
        int y = get_random(1, n-1);
        if (actual[x][y] != '0')
            continue;
        query[x][y] = '1';
        query[x][0] = '1';
        print_query();
        cin >> res;
        query[x][y] = '0';
        query[x][0] = '0';

        if (actual[x][0] == 'V') {
            if (res == n * 2) {
                actual[x][y] = 'V';
                eras(columns, y);
            } else {
                actual[x][y] = 'H';
                eras(rows, x);
            }
        } else {
            if (res == n) {
                actual[x][y] = 'H';
                eras(rows, x);
            } else {
                actual[x][y] = 'V';
                eras(columns, y);
            }
        }

    }

    if (rows.empty())
        print_ans('H');
    else
        print_ans('V');

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...