Submission #237907

# Submission time Handle Problem Language Result Execution time Memory
237907 2020-06-09T09:25:54 Z lyc The Big Prize (IOI17_prize) C++14
100 / 100
65 ms 900 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cout << #x << " :: " << x << endl;
#define _ << " " <<

const int mxN = 2e5+5;
const int mxQ = 10000;
int n, q = 0;
map<int,vector<int>> cache;

vector<int> query(int i) {
    //TRACE("QUERY" _ i);
    assert(i >= 0 && i < n);
    if (cache.count(i)) return cache[i];
    assert(++q <= mxQ);
    return cache[i] = ask(i);
}

int find_best(int _n) {
    n = _n;
    int mxc = 0;
    int b = 473, cnt = 0;
    for (int i = 0; i < n; i += b) {
        auto res = query(i);
        mxc = max(mxc,res[0]+res[1]);
        ++cnt;
    }
    if (cnt) for (int i = 1; i <= min(n,473)-cnt; ++i) {
        auto res = query(i);
        mxc = max(mxc,res[0]+res[1]);
        ++cnt;
    }
    int pre = 0;
    for (int i = 0; i < n;) {
        auto res = query(i);
        int c = res[0]+res[1];
        if (c == 0) return i;
        pre += (c == mxc);
        auto it = cache.upper_bound(i);
        while (it != cache.end()) {
            auto y = it->second;
            if (y[0]+y[1] == mxc && y[0] == i+1-pre) ++it;
            else break;
        }
        int lo = prev(it)->first, hi = (it == cache.end() ? n : it->first);
        while (hi-lo > 1) {
            int mid = (lo+hi)/2;
            auto y = query(mid);
            if (y[0]+y[1] == mxc && y[0] == i+1-pre) lo = mid;
            else hi = mid;
        }
        pre += hi-i-1;
        i = hi;
    }
    assert(false);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 9 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 9 ms 384 KB Output is correct
5 Correct 9 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 10 ms 384 KB Output is correct
8 Correct 8 ms 632 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 9 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 384 KB Output is correct
2 Correct 7 ms 420 KB Output is correct
3 Correct 9 ms 384 KB Output is correct
4 Correct 8 ms 384 KB Output is correct
5 Correct 9 ms 384 KB Output is correct
6 Correct 9 ms 384 KB Output is correct
7 Correct 11 ms 376 KB Output is correct
8 Correct 11 ms 384 KB Output is correct
9 Correct 12 ms 384 KB Output is correct
10 Correct 10 ms 384 KB Output is correct
11 Correct 10 ms 384 KB Output is correct
12 Correct 8 ms 384 KB Output is correct
13 Correct 11 ms 504 KB Output is correct
14 Correct 9 ms 384 KB Output is correct
15 Correct 15 ms 504 KB Output is correct
16 Correct 38 ms 760 KB Output is correct
17 Correct 12 ms 384 KB Output is correct
18 Correct 60 ms 760 KB Output is correct
19 Correct 11 ms 512 KB Output is correct
20 Correct 15 ms 560 KB Output is correct
21 Correct 22 ms 504 KB Output is correct
22 Correct 15 ms 384 KB Output is correct
23 Correct 9 ms 376 KB Output is correct
24 Correct 11 ms 384 KB Output is correct
25 Correct 29 ms 632 KB Output is correct
26 Correct 37 ms 632 KB Output is correct
27 Correct 11 ms 376 KB Output is correct
28 Correct 40 ms 760 KB Output is correct
29 Correct 30 ms 632 KB Output is correct
30 Correct 65 ms 776 KB Output is correct
31 Correct 11 ms 384 KB Output is correct
32 Correct 8 ms 440 KB Output is correct
33 Correct 6 ms 256 KB Output is correct
34 Correct 27 ms 488 KB Output is correct
35 Correct 7 ms 440 KB Output is correct
36 Correct 22 ms 504 KB Output is correct
37 Correct 9 ms 384 KB Output is correct
38 Correct 9 ms 384 KB Output is correct
39 Correct 26 ms 504 KB Output is correct
40 Correct 27 ms 752 KB Output is correct
41 Correct 42 ms 628 KB Output is correct
42 Correct 44 ms 632 KB Output is correct
43 Correct 38 ms 632 KB Output is correct
44 Correct 32 ms 504 KB Output is correct
45 Correct 20 ms 484 KB Output is correct
46 Correct 11 ms 384 KB Output is correct
47 Correct 24 ms 504 KB Output is correct
48 Correct 47 ms 632 KB Output is correct
49 Correct 15 ms 384 KB Output is correct
50 Correct 39 ms 852 KB Output is correct
51 Correct 32 ms 508 KB Output is correct
52 Correct 8 ms 412 KB Output is correct
53 Correct 12 ms 384 KB Output is correct
54 Correct 25 ms 504 KB Output is correct
55 Correct 9 ms 384 KB Output is correct
56 Correct 51 ms 760 KB Output is correct
57 Correct 48 ms 632 KB Output is correct
58 Correct 48 ms 676 KB Output is correct
59 Correct 36 ms 632 KB Output is correct
60 Correct 28 ms 704 KB Output is correct
61 Correct 10 ms 376 KB Output is correct
62 Correct 8 ms 376 KB Output is correct
63 Correct 9 ms 376 KB Output is correct
64 Correct 9 ms 376 KB Output is correct
65 Correct 9 ms 360 KB Output is correct
66 Correct 18 ms 384 KB Output is correct
67 Correct 9 ms 384 KB Output is correct
68 Correct 9 ms 440 KB Output is correct
69 Correct 9 ms 436 KB Output is correct
70 Correct 9 ms 384 KB Output is correct
71 Correct 47 ms 900 KB Output is correct
72 Correct 12 ms 384 KB Output is correct
73 Correct 47 ms 764 KB Output is correct
74 Correct 50 ms 888 KB Output is correct
75 Correct 9 ms 384 KB Output is correct
76 Correct 46 ms 760 KB Output is correct
77 Correct 63 ms 752 KB Output is correct
78 Correct 11 ms 512 KB Output is correct
79 Correct 35 ms 764 KB Output is correct
80 Correct 65 ms 760 KB Output is correct
81 Correct 41 ms 748 KB Output is correct
82 Correct 45 ms 760 KB Output is correct
83 Correct 11 ms 384 KB Output is correct
84 Correct 45 ms 760 KB Output is correct
85 Correct 49 ms 764 KB Output is correct
86 Correct 39 ms 768 KB Output is correct
87 Correct 12 ms 384 KB Output is correct
88 Correct 42 ms 760 KB Output is correct
89 Correct 47 ms 760 KB Output is correct
90 Correct 11 ms 384 KB Output is correct
91 Correct 30 ms 632 KB Output is correct
92 Correct 61 ms 760 KB Output is correct
93 Correct 57 ms 760 KB Output is correct
94 Correct 46 ms 792 KB Output is correct
95 Correct 43 ms 888 KB Output is correct
96 Correct 59 ms 760 KB Output is correct
97 Correct 56 ms 760 KB Output is correct