Submission #421155

# Submission time Handle Problem Language Result Execution time Memory
421155 2021-06-08T19:23:41 Z MarcoMeijer The Big Prize (IOI17_prize) C++14
100 / 100
63 ms 956 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int big=0;
int n;

vi Ask(int i) {
    static map<int,vi> mem;
    auto it = mem.find(i);
    if(it != mem.end())
        return it->second;
    return mem[i] = ask(i);
}

int getSum(int i) {
    if(i < 0 || i >= n) return big;
    return Ask(i)[0] + Ask(i)[1];
}

int getBiggestSize(int lb, int ub, int dep=9) {
    if(dep == 0) return 0;
    int mid = (lb+ub)/2;
    int res = getSum(mid);
    res = max(res, getBiggestSize(lb,mid-1,dep-1));
    res = max(res, getBiggestSize(mid+1,ub,dep-1));
    return res;
}

int getIndex(int i) {
    int lb=0, ub=n-1;
    while(lb < ub) {
        int mid=(lb+ub)/2;
        int sm = getSum(mid);
        int len = 0;
        if(sm != big) {
            while(sm != big) sm = getSum(++mid);
            sm = getSum(--mid);
            while(sm != big) sm = getSum(--mid), len++;
            int res = mid == -1 ? 0 : Ask(mid)[0];
            if(i >= res && i < res+len)
                return mid + 1 + i - res;
            if(res > i) ub = mid-1;
            else lb = mid+len+1;
            continue;
        }
        int res = Ask(mid)[0];
        if(res > i) ub = mid-1;
        else lb = mid+1;
    }
    return lb;
}

int find_best(int N) {
    n = N;
    if(n <= 5000) {
        RE(i,n) {
            int res = getSum(i);
            if(res == 0)
                return i;
        }
    }


    big = getBiggestSize(0,n-1);

    RE(i,big) {
        int j = getIndex(i);
        if(getSum(j) == 0)
            return j;
    }

    return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 328 KB Output is correct
2 Correct 4 ms 320 KB Output is correct
3 Correct 3 ms 324 KB Output is correct
4 Correct 7 ms 328 KB Output is correct
5 Correct 6 ms 312 KB Output is correct
6 Correct 6 ms 320 KB Output is correct
7 Correct 10 ms 336 KB Output is correct
8 Correct 7 ms 276 KB Output is correct
9 Correct 3 ms 320 KB Output is correct
10 Correct 5 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 280 KB Output is correct
2 Correct 5 ms 268 KB Output is correct
3 Correct 5 ms 284 KB Output is correct
4 Correct 7 ms 280 KB Output is correct
5 Correct 3 ms 316 KB Output is correct
6 Correct 3 ms 380 KB Output is correct
7 Correct 7 ms 320 KB Output is correct
8 Correct 7 ms 292 KB Output is correct
9 Correct 3 ms 360 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 8 ms 328 KB Output is correct
12 Correct 8 ms 328 KB Output is correct
13 Correct 11 ms 328 KB Output is correct
14 Correct 7 ms 328 KB Output is correct
15 Correct 6 ms 404 KB Output is correct
16 Correct 41 ms 748 KB Output is correct
17 Correct 6 ms 288 KB Output is correct
18 Correct 47 ms 956 KB Output is correct
19 Correct 7 ms 320 KB Output is correct
20 Correct 16 ms 328 KB Output is correct
21 Correct 26 ms 448 KB Output is correct
22 Correct 11 ms 328 KB Output is correct
23 Correct 6 ms 288 KB Output is correct
24 Correct 5 ms 308 KB Output is correct
25 Correct 26 ms 448 KB Output is correct
26 Correct 22 ms 540 KB Output is correct
27 Correct 5 ms 320 KB Output is correct
28 Correct 24 ms 660 KB Output is correct
29 Correct 33 ms 576 KB Output is correct
30 Correct 52 ms 704 KB Output is correct
31 Correct 7 ms 284 KB Output is correct
32 Correct 4 ms 344 KB Output is correct
33 Correct 1 ms 200 KB Output is correct
34 Correct 10 ms 444 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
36 Correct 17 ms 412 KB Output is correct
37 Correct 8 ms 280 KB Output is correct
38 Correct 7 ms 328 KB Output is correct
39 Correct 31 ms 448 KB Output is correct
40 Correct 50 ms 704 KB Output is correct
41 Correct 16 ms 580 KB Output is correct
42 Correct 31 ms 576 KB Output is correct
43 Correct 34 ms 532 KB Output is correct
44 Correct 25 ms 496 KB Output is correct
45 Correct 20 ms 404 KB Output is correct
46 Correct 6 ms 280 KB Output is correct
47 Correct 30 ms 452 KB Output is correct
48 Correct 36 ms 576 KB Output is correct
49 Correct 11 ms 320 KB Output is correct
50 Correct 54 ms 752 KB Output is correct
51 Correct 20 ms 388 KB Output is correct
52 Correct 8 ms 288 KB Output is correct
53 Correct 5 ms 280 KB Output is correct
54 Correct 23 ms 432 KB Output is correct
55 Correct 5 ms 276 KB Output is correct
56 Correct 62 ms 660 KB Output is correct
57 Correct 35 ms 616 KB Output is correct
58 Correct 35 ms 556 KB Output is correct
59 Correct 37 ms 540 KB Output is correct
60 Correct 33 ms 452 KB Output is correct
61 Correct 3 ms 344 KB Output is correct
62 Correct 7 ms 280 KB Output is correct
63 Correct 6 ms 284 KB Output is correct
64 Correct 9 ms 320 KB Output is correct
65 Correct 7 ms 304 KB Output is correct
66 Correct 55 ms 340 KB Output is correct
67 Correct 13 ms 320 KB Output is correct
68 Correct 34 ms 352 KB Output is correct
69 Correct 59 ms 324 KB Output is correct
70 Correct 14 ms 320 KB Output is correct
71 Correct 60 ms 704 KB Output is correct
72 Correct 10 ms 328 KB Output is correct
73 Correct 55 ms 668 KB Output is correct
74 Correct 60 ms 704 KB Output is correct
75 Correct 6 ms 328 KB Output is correct
76 Correct 52 ms 676 KB Output is correct
77 Correct 60 ms 744 KB Output is correct
78 Correct 10 ms 328 KB Output is correct
79 Correct 31 ms 552 KB Output is correct
80 Correct 31 ms 748 KB Output is correct
81 Correct 63 ms 704 KB Output is correct
82 Correct 54 ms 724 KB Output is correct
83 Correct 8 ms 332 KB Output is correct
84 Correct 44 ms 688 KB Output is correct
85 Correct 59 ms 704 KB Output is correct
86 Correct 56 ms 740 KB Output is correct
87 Correct 10 ms 328 KB Output is correct
88 Correct 29 ms 704 KB Output is correct
89 Correct 51 ms 796 KB Output is correct
90 Correct 8 ms 328 KB Output is correct
91 Correct 36 ms 588 KB Output is correct
92 Correct 58 ms 704 KB Output is correct
93 Correct 30 ms 748 KB Output is correct
94 Correct 45 ms 708 KB Output is correct
95 Correct 45 ms 704 KB Output is correct
96 Correct 55 ms 736 KB Output is correct
97 Correct 44 ms 716 KB Output is correct