Submission #893299

# Submission time Handle Problem Language Result Execution time Memory
893299 2023-12-26T21:34:08 Z box Library (JOI18_library) C++17
100 / 100
243 ms 688 KB
#include <bits/stdc++.h>
using namespace std;

#define ar array
#define sz(v) int(std::size(v))
using i64 = long long;
using pii = pair<int, int>;

#include "library.h"

void Solve(int n) {
    if (n == 1) {
        Answer({1});
        return;
    }
    vector<pii> edges;
    auto expected = [&](vector<int> v) {
        int save = 0;
        for (auto [i, j] : edges) save += v[i] && v[j];
        return count(begin(v), end(v), 1) - save;
    };
    for (int rep = 0; rep < n - 1; rep++) {
        int low = 0, hi = n - 1;
        while (low < hi) {
            int mid = (low + hi) / 2;
            vector<int> v(n);
            fill(begin(v), begin(v) + mid + 1, 1);
            Query(v) < expected(v) ? hi = mid : low = mid + 1;
        }
        int x = low;
        low = 0, hi = x - 1;
        while (low < hi) {
            int mid = (low + hi) / 2 + 1;
            vector<int> v(n);
            fill(begin(v) + mid, begin(v) + x + 1, 1);
            Query(v) < expected(v) ? low = mid : hi = mid - 1;
        }
        edges.push_back({low, x});
    }
    vector<vector<int>> adj(n);
    for (auto [i, j] : edges) adj[i].push_back(j), adj[j].push_back(i);
    int src = -1;
    for (int i = 0; i < n; i++) if (sz(adj[i]) == 1) src = i;
    vector<int> ans{{src, adj[src][0]}};
    while (sz(ans) < n) ans.push_back(adj[end(ans)[-1]][0] ^ adj[end(ans)[-1]][1] ^ end(ans)[-2]);
    for (int &x : ans) x++;
    Answer(ans);
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 432 KB # of queries: 2793
2 Correct 22 ms 444 KB # of queries: 2772
3 Correct 22 ms 436 KB # of queries: 2917
4 Correct 25 ms 436 KB # of queries: 2923
5 Correct 28 ms 436 KB # of queries: 2909
6 Correct 28 ms 432 KB # of queries: 2915
7 Correct 22 ms 432 KB # of queries: 2929
8 Correct 27 ms 668 KB # of queries: 2799
9 Correct 29 ms 432 KB # of queries: 2922
10 Correct 13 ms 684 KB # of queries: 1707
11 Correct 0 ms 596 KB # of queries: 0
12 Correct 0 ms 340 KB # of queries: 1
13 Correct 0 ms 344 KB # of queries: 4
14 Correct 0 ms 344 KB # of queries: 10
15 Correct 2 ms 344 KB # of queries: 100
16 Correct 2 ms 432 KB # of queries: 226
# Verdict Execution time Memory Grader output
1 Correct 18 ms 432 KB # of queries: 2793
2 Correct 22 ms 444 KB # of queries: 2772
3 Correct 22 ms 436 KB # of queries: 2917
4 Correct 25 ms 436 KB # of queries: 2923
5 Correct 28 ms 436 KB # of queries: 2909
6 Correct 28 ms 432 KB # of queries: 2915
7 Correct 22 ms 432 KB # of queries: 2929
8 Correct 27 ms 668 KB # of queries: 2799
9 Correct 29 ms 432 KB # of queries: 2922
10 Correct 13 ms 684 KB # of queries: 1707
11 Correct 0 ms 596 KB # of queries: 0
12 Correct 0 ms 340 KB # of queries: 1
13 Correct 0 ms 344 KB # of queries: 4
14 Correct 0 ms 344 KB # of queries: 10
15 Correct 2 ms 344 KB # of queries: 100
16 Correct 2 ms 432 KB # of queries: 226
17 Correct 226 ms 440 KB # of queries: 19260
18 Correct 215 ms 440 KB # of queries: 19010
19 Correct 242 ms 688 KB # of queries: 19240
20 Correct 181 ms 676 KB # of queries: 18005
21 Correct 198 ms 436 KB # of queries: 16917
22 Correct 239 ms 436 KB # of queries: 19279
23 Correct 243 ms 440 KB # of queries: 19218
24 Correct 88 ms 436 KB # of queries: 8875
25 Correct 234 ms 436 KB # of queries: 18825
26 Correct 208 ms 440 KB # of queries: 17599
27 Correct 91 ms 440 KB # of queries: 8842
28 Correct 205 ms 436 KB # of queries: 17944
29 Correct 217 ms 436 KB # of queries: 17924
30 Correct 201 ms 440 KB # of queries: 17944