Submission #519987

# Submission time Handle Problem Language Result Execution time Memory
519987 2022-01-28T01:15:21 Z tabr The Big Prize (IOI17_prize) C++17
100 / 100
56 ms 5632 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

#ifdef tabr
function<vector<int>(int)> ask;
#else
#include "prize.h"
#endif

int find_best(int n) {
    if (n <= 5000) {
        for (int i = 0; i < n; i++) {
            auto a = ask(i);
            if (a[0] + a[1] == 0) {
                return i;
            }
        }
        assert(false);
    }
    vector<vector<int>> res(n);
    map<int, map<int, int>> mp;
    auto Ask = [&](int i) {
        if (!res[i].empty()) {
            return res[i][0] + res[i][1];
        }
        res[i] = ask(i);
        mp[res[i][0] + res[i][1]][i] = res[i][0];
        return res[i][0] + res[i][1];
    };
    function<void(int, int)> solve = [&](int low, int high) {
        if (low == high) {
            return;
        }
        int mid = (high + low) >> 1;
        if (Ask(mid) == 0) {
            return;
        }
        mp[Ask(mid)][mid] = res[mid][0];
        auto iter = mp[Ask(mid)].find(mid);
        if (iter == mp[Ask(mid)].begin() || prev(iter)->second < res[mid][0]) {
            solve(low, mid);
        }
        if (iter == prev(mp[Ask(mid)].end()) || next(iter)->second > res[mid][0]) {
            solve(mid + 1, high);
        }
    };
    solve(0, n);
    for (int i = 0; i < n; i++) {
        if (!res[i].empty() && Ask(i) == 0) {
            return i;
        }
    }
    return -1;
}

#ifdef tabr
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> k;
    vector<int> c(k);
    for (int i = 0; i < k; i++) {
        cin >> c[i];
    }
    int n = accumulate(c.begin(), c.end(), 0);
    vector<int> p;
    for (int i = 0; i < k; i++) {
        for (int j = 0; j < c[i]; j++) {
            p.emplace_back(i);
        }
    }
    mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
    shuffle(p.begin(), p.end(), rng);
    ask = [&](int i) {
        vector<int> res(2);
        for (int j = 0; j < i; j++) {
            if (p[j] < p[i]) {
                res[0]++;
            }
        }
        for (int j = i + 1; j < n; j++) {
            if (p[j] < p[i]) {
                res[1]++;
            }
        }
        return res;
    };
    debug(p);
    int id = find_best(n);
    debug(id);
    assert(p[id] == 0);
    return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4936 KB Output is correct
2 Correct 3 ms 4880 KB Output is correct
3 Correct 3 ms 4900 KB Output is correct
4 Correct 3 ms 4880 KB Output is correct
5 Correct 3 ms 4892 KB Output is correct
6 Correct 3 ms 4888 KB Output is correct
7 Correct 2 ms 4892 KB Output is correct
8 Correct 3 ms 4936 KB Output is correct
9 Correct 3 ms 4936 KB Output is correct
10 Correct 3 ms 4936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5060 KB Output is correct
2 Correct 3 ms 4996 KB Output is correct
3 Correct 4 ms 4936 KB Output is correct
4 Correct 3 ms 4872 KB Output is correct
5 Correct 3 ms 4892 KB Output is correct
6 Correct 3 ms 5000 KB Output is correct
7 Correct 3 ms 4936 KB Output is correct
8 Correct 3 ms 4896 KB Output is correct
9 Correct 3 ms 4884 KB Output is correct
10 Correct 4 ms 4944 KB Output is correct
11 Correct 5 ms 5004 KB Output is correct
12 Correct 6 ms 5016 KB Output is correct
13 Correct 7 ms 5012 KB Output is correct
14 Correct 10 ms 840 KB Output is correct
15 Correct 47 ms 5312 KB Output is correct
16 Correct 49 ms 5308 KB Output is correct
17 Correct 22 ms 5340 KB Output is correct
18 Correct 22 ms 5348 KB Output is correct
19 Correct 26 ms 5528 KB Output is correct
20 Correct 21 ms 2768 KB Output is correct
21 Correct 47 ms 5288 KB Output is correct
22 Correct 33 ms 5180 KB Output is correct
23 Correct 4 ms 4892 KB Output is correct
24 Correct 8 ms 4956 KB Output is correct
25 Correct 35 ms 5260 KB Output is correct
26 Correct 43 ms 5264 KB Output is correct
27 Correct 4 ms 4980 KB Output is correct
28 Correct 37 ms 5204 KB Output is correct
29 Correct 37 ms 5220 KB Output is correct
30 Correct 51 ms 5284 KB Output is correct
31 Correct 30 ms 5248 KB Output is correct
32 Correct 7 ms 4936 KB Output is correct
33 Correct 0 ms 200 KB Output is correct
34 Correct 51 ms 5284 KB Output is correct
35 Correct 4 ms 5024 KB Output is correct
36 Correct 47 ms 5268 KB Output is correct
37 Correct 7 ms 5020 KB Output is correct
38 Correct 4 ms 4936 KB Output is correct
39 Correct 49 ms 5244 KB Output is correct
40 Correct 45 ms 5252 KB Output is correct
41 Correct 38 ms 5312 KB Output is correct
42 Correct 47 ms 5272 KB Output is correct
43 Correct 46 ms 5316 KB Output is correct
44 Correct 22 ms 5396 KB Output is correct
45 Correct 43 ms 5212 KB Output is correct
46 Correct 41 ms 5380 KB Output is correct
47 Correct 42 ms 5308 KB Output is correct
48 Correct 42 ms 5224 KB Output is correct
49 Correct 48 ms 5308 KB Output is correct
50 Correct 31 ms 5460 KB Output is correct
51 Correct 31 ms 5268 KB Output is correct
52 Correct 51 ms 5268 KB Output is correct
53 Correct 3 ms 5044 KB Output is correct
54 Correct 38 ms 5268 KB Output is correct
55 Correct 34 ms 5240 KB Output is correct
56 Correct 40 ms 5260 KB Output is correct
57 Correct 41 ms 5232 KB Output is correct
58 Correct 31 ms 5268 KB Output is correct
59 Correct 30 ms 5360 KB Output is correct
60 Correct 48 ms 5328 KB Output is correct
61 Correct 4 ms 5004 KB Output is correct
62 Correct 4 ms 4884 KB Output is correct
63 Correct 4 ms 4892 KB Output is correct
64 Correct 4 ms 4928 KB Output is correct
65 Correct 3 ms 4980 KB Output is correct
66 Correct 3 ms 4936 KB Output is correct
67 Correct 4 ms 5000 KB Output is correct
68 Correct 3 ms 4892 KB Output is correct
69 Correct 3 ms 4936 KB Output is correct
70 Correct 4 ms 4936 KB Output is correct
71 Correct 47 ms 5632 KB Output is correct
72 Correct 8 ms 4936 KB Output is correct
73 Correct 40 ms 5276 KB Output is correct
74 Correct 44 ms 5300 KB Output is correct
75 Correct 5 ms 5036 KB Output is correct
76 Correct 39 ms 5192 KB Output is correct
77 Correct 47 ms 5312 KB Output is correct
78 Correct 8 ms 4936 KB Output is correct
79 Correct 27 ms 5108 KB Output is correct
80 Correct 51 ms 5292 KB Output is correct
81 Correct 37 ms 5308 KB Output is correct
82 Correct 53 ms 5280 KB Output is correct
83 Correct 5 ms 4936 KB Output is correct
84 Correct 42 ms 5180 KB Output is correct
85 Correct 56 ms 5344 KB Output is correct
86 Correct 9 ms 4936 KB Output is correct
87 Correct 5 ms 4936 KB Output is correct
88 Correct 8 ms 5024 KB Output is correct
89 Correct 7 ms 4936 KB Output is correct
90 Correct 4 ms 4936 KB Output is correct
91 Correct 6 ms 5028 KB Output is correct
92 Correct 4 ms 4936 KB Output is correct
93 Correct 6 ms 5064 KB Output is correct
94 Correct 7 ms 4936 KB Output is correct
95 Correct 6 ms 4936 KB Output is correct
96 Correct 6 ms 4936 KB Output is correct
97 Correct 3 ms 4936 KB Output is correct