Submission #1048426

# Submission time Handle Problem Language Result Execution time Memory
1048426 2024-08-08T07:31:07 Z 우민규(#11036) Light Bulbs (EGOI24_lightbulbs) C++17
80 / 100
4 ms 596 KB
#include <bits/stdc++.h>
using namespace std;

int n;

int ask_cartesian(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;
}

int ask_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 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_cartesian({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;
}

bool same_orientation(pair<int, int> a, pair<int, int> b) {
    int res = ask_xy({a, b});
    // orientation is different -> 2 * n - 1
    return res != 2 * n - 1;
}

void solve() {
    cin >> n;

    vector<pair<int, int>> verticals, horizontals;

    int x0, y0;

    if (vertical_cnt(0, {0})) {
        verticals.push_back({0, 0});
        x0 = 1, y0 = 0;
    } else {
        horizontals.push_back({0, 0});
        x0 = 0, y0 = 1;
    }

    while (x0 < n && y0 < n) {
        if (!verticals.empty()) {
            if (same_orientation({x0, y0}, verticals[0])) {
                verticals.push_back({x0, y0});
                x0 += 1;
            } else {
                horizontals.push_back({x0, y0});
                y0 += 1;
            }
        } else {
            if (same_orientation({x0, y0}, horizontals[0])) {
                horizontals.push_back({x0, y0});
                y0 += 1;
            } else {
                verticals.push_back({x0, y0});
                x0 += 1;
            }

        }
    }

    if (x0 == n) {
        answer_xy(verticals);
    } else if (y0 == n) {
        answer_xy(horizontals);
    }

}

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:49:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     if (res == ys.size() * n) return 0;
      |         ~~~~^~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:106:9: warning: unused variable 't' [-Wunused-variable]
  106 |     int t = 1;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 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 1 ms 344 KB Output is correct
17 Correct 0 ms 380 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 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
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 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 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 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 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 1 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 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 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 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 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 340 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 1 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 1 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 1 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 1 ms 344 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 0 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 Partially correct 1 ms 480 KB Partially correct
60 Partially correct 1 ms 472 KB Partially correct
61 Partially correct 1 ms 472 KB Partially correct
62 Partially correct 2 ms 480 KB Partially correct
63 Partially correct 2 ms 472 KB Partially correct
64 Partially correct 2 ms 472 KB Partially correct
65 Partially correct 2 ms 480 KB Partially correct
66 Partially correct 2 ms 480 KB Partially correct
67 Partially correct 4 ms 472 KB Partially correct
68 Partially correct 2 ms 472 KB Partially correct
69 Partially correct 2 ms 480 KB Partially correct
70 Partially correct 1 ms 472 KB Partially correct
71 Partially correct 1 ms 472 KB Partially correct
72 Partially correct 1 ms 472 KB Partially correct
73 Partially correct 1 ms 472 KB Partially correct
74 Partially correct 2 ms 480 KB Partially correct
75 Partially correct 1 ms 472 KB Partially correct
76 Partially correct 2 ms 472 KB Partially correct
77 Partially correct 2 ms 472 KB Partially correct
78 Partially correct 1 ms 472 KB Partially correct
79 Partially correct 2 ms 480 KB Partially correct
80 Partially correct 3 ms 468 KB Partially correct
81 Partially correct 2 ms 468 KB Partially correct
82 Partially correct 2 ms 480 KB Partially correct
83 Partially correct 2 ms 488 KB Partially correct
84 Partially correct 2 ms 472 KB Partially correct
85 Partially correct 2 ms 592 KB Partially correct
86 Partially correct 3 ms 528 KB Partially correct
87 Partially correct 2 ms 480 KB Partially correct
88 Partially correct 2 ms 472 KB Partially correct
89 Partially correct 2 ms 540 KB Partially correct
90 Partially correct 2 ms 480 KB Partially correct
91 Partially correct 2 ms 472 KB Partially correct
92 Partially correct 2 ms 480 KB Partially correct
93 Partially correct 2 ms 472 KB Partially correct
94 Partially correct 2 ms 472 KB Partially correct
95 Partially correct 1 ms 472 KB Partially correct
96 Partially correct 3 ms 472 KB Partially correct
97 Correct 0 ms 344 KB Output is correct