Submission #1048186

# Submission time Handle Problem Language Result Execution time Memory
1048186 2024-08-08T04:28:58 Z 우민규(#11036) Light Bulbs (EGOI24_lightbulbs) C++17
55.8656 / 100
17 ms 1028 KB
#include <bits/stdc++.h>
using namespace std;

int n;

int ask_xy(vector<int> xs, vector<int> ys) {
    vector<string> out(n, string(n, '0'));
    for (auto x : xs) for (auto y : ys) out[y][x] = '1';
    cout << "?\n";
    for (int i = 0; i < n; ++i) cout << out[i] << "\n";
    cout << flush;
    int res;
    cin >> res;
    return res;
}

void answer_xy(vector<pair<int, int>> xys) {
    vector<string> out(n, string(n, '0'));
    for (auto [x, y] : xys) out[y][x] = '1';
    cout << "!\n";
    for (int i = 0; i < n; ++i) cout << out[i] << "\n";
    cout << flush;
}

int vertical_cnt(int x, vector<int> ys) {
    if (ys.size() == 1) {
        int none0 = -1, none1 = -1;
        for (int j = 0; j < n; ++j) {
            if (find(ys.begin(), ys.end(), j) == ys.end()) {
                if (none0 == -1) none0 = j;
                else none1 = j;
            }
        }
        return vertical_cnt(x, {ys[0], none0, none1}) - vertical_cnt(x, {none0, none1});
    }
    int res = ask_xy({x}, ys);
    if (res == n) return ys.size();
    if (res == ys.size() * n) return 0;
    int horiz_cnt = (res - n) / (n - 1);
    return ys.size() - horiz_cnt;
}

// finds a vertical light if it exists
int find_vertical(int x, vector<int> ys) {
    if (ys.size() == 1) {
        return ys[0];
    }
    vector<int> yl, yr;
    for (int i = 0; i < ys.size(); ++i) {
        if (i % 2) yl.push_back(ys[i]);
        else yr.push_back(ys[i]);
    }
    if (vertical_cnt(x, yl) == 0) {
        return find_vertical(x, yr);
    } else {
        return find_vertical(x, yl);
    }
}

void solve() {
    cin >> n;
    vector<int> xs;
    vector<pair<int, int>> xys;
    for (int x = 0; x < n; ++x) {
        vector<int> ys(n);
        iota(ys.begin(), ys.end(), 0);
        if (vertical_cnt(x, ys) == 0) {
            xys.clear();
            for (int i = 0; i < n; ++i) xys.push_back({x, i});
            answer_xy(xys);
            return;
        } else {
            int y = find_vertical(x, ys);
            xys.push_back({x, y});
        }
    }
    answer_xy(xys);
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    solve();
}

Compilation message

Main.cpp: In function 'int vertical_cnt(int, std::vector<int>)':
Main.cpp:38:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     if (res == ys.size() * n) return 0;
      |         ~~~~^~~~~~~~~~~~~~~~
Main.cpp: In function 'int find_vertical(int, std::vector<int>)':
Main.cpp:49:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for (int i = 0; i < ys.size(); ++i) {
      |                     ~~^~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:82:9: warning: unused variable 't' [-Wunused-variable]
   82 |     int t = 1;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 0 ms 596 KB Output is correct
14 Correct 1 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
# Verdict Execution time Memory 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 1 ms 344 KB Output is correct
18 Correct 1 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 0 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 0 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 0 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 0 ms 344 KB Output is correct
42 Correct 1 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 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 0 ms 344 KB Output is correct
52 Correct 1 ms 388 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 0 ms 344 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory 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 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 1 ms 344 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 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 1 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 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 1 ms 344 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 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 1 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 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 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 1 ms 344 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 0 ms 344 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Partially correct 9 ms 592 KB Partially correct
61 Partially correct 10 ms 472 KB Partially correct
62 Partially correct 12 ms 516 KB Partially correct
63 Partially correct 10 ms 480 KB Partially correct
64 Partially correct 17 ms 484 KB Partially correct
65 Partially correct 11 ms 728 KB Partially correct
66 Partially correct 14 ms 480 KB Partially correct
67 Partially correct 11 ms 640 KB Partially correct
68 Partially correct 11 ms 568 KB Partially correct
69 Partially correct 10 ms 472 KB Partially correct
70 Partially correct 11 ms 568 KB Partially correct
71 Partially correct 13 ms 712 KB Partially correct
72 Partially correct 14 ms 648 KB Partially correct
73 Partially correct 11 ms 480 KB Partially correct
74 Partially correct 13 ms 684 KB Partially correct
75 Correct 0 ms 344 KB Output is correct
76 Partially correct 2 ms 480 KB Partially correct
77 Partially correct 9 ms 472 KB Partially correct
78 Partially correct 11 ms 624 KB Partially correct
79 Partially correct 4 ms 480 KB Partially correct
80 Partially correct 5 ms 480 KB Partially correct
81 Partially correct 9 ms 480 KB Partially correct
82 Partially correct 10 ms 808 KB Partially correct
83 Partially correct 10 ms 476 KB Partially correct
84 Partially correct 10 ms 480 KB Partially correct
85 Partially correct 10 ms 472 KB Partially correct
86 Partially correct 12 ms 480 KB Partially correct
87 Partially correct 13 ms 604 KB Partially correct
88 Partially correct 10 ms 724 KB Partially correct
89 Partially correct 10 ms 592 KB Partially correct
90 Partially correct 13 ms 668 KB Partially correct
91 Partially correct 15 ms 480 KB Partially correct
92 Partially correct 10 ms 480 KB Partially correct
93 Partially correct 10 ms 480 KB Partially correct
94 Partially correct 12 ms 1028 KB Partially correct
95 Partially correct 12 ms 480 KB Partially correct
96 Partially correct 11 ms 656 KB Partially correct
97 Correct 0 ms 344 KB Output is correct