Submission #316331

# Submission time Handle Problem Language Result Execution time Memory
316331 2020-10-25T21:55:19 Z nikatamliani The Big Prize (IOI17_prize) C++14
94.89 / 100
62 ms 5396 KB
#include <bits/stdc++.h>
using namespace std;
#include "prize.h"
vector < vector < int > > memo;
vector < int > memo_ask(int x) {
    if(!memo[x].empty()) return memo[x];
    return memo[x] = ask(x);
}
int find_best(int n) {
    int next = -1, at_most = min(472, n - 1);
    const int BLOCK_SIZE = 500;
    vector < int > bad(2); 
    memo.resize(n);
    int limit = 40, cnt = 0; 
    for(int i = 0; i <= at_most; ++i) {
        vector < int > cur = memo_ask(i);
        if(bad[0] + bad[1] <= cur[0] + cur[1]) bad = cur;
        if(cur[0] == 0 && cur[1] == 0) return i;
    }
  	for(int i = 0; i <= at_most; ++i) {
      	if(bad[0] + bad[1] != memo_ask(i)[0] + memo_ask(i)[1]) {
          	++cnt;
        }
  	}
  	vector < int > bad0 = bad, bad1(2);
  	if(cnt > limit) {
  	    for(int i = 0; i <= at_most; ++i) {
  	        if(bad[0] + bad[1] != memo_ask(i)[0] + memo_ask(i)[1]) {
  	            bad1 = memo_ask(i);
            }
  	    }
  	}
    for(int i = at_most + 1; i < n; i = next + 1) {
        int l = i, r = n - 1; next = -1;
        vector < int > t = memo_ask(i);
        if(t[0] + t[1] != bad0[0] + bad0[1]) {
            ++cnt;
            if(cnt <= limit) {
                if(bad1[0] + bad1[1] <= t[0] + t[1]) {
                    bad1 = t;
                }
            } else {
                bad1[0]++;
                bad1[1]--;
            }
            next = i;
            if(t[0] == 0 && t[1] == 0) return i; 
            continue;
        } 
        bad0 = t;
        int maybe = i + BLOCK_SIZE;
        if(maybe < n) {
            if(memo_ask(maybe) == bad0 || memo_ask(maybe) == bad1) {
                next = maybe; 
                continue;
            }
        }
        if(maybe < n) r = maybe - 1;
        while(r >= l) {
            int m = l + r >> 1;
            if(memo_ask(m) == bad0) {
                next = m;
                l = m + 1;
            } else {
                r = m - 1; 
            }
        }
        assert(next >= i);
    }
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:60:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |             int m = l + r >> 1;
      |                     ~~^~~
prize.cpp:12:25: warning: control reaches end of non-void function [-Wreturn-type]
   12 |     vector < int > bad(2);
      |                         ^
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4992 KB Output is correct
2 Correct 10 ms 5096 KB Output is correct
3 Correct 12 ms 4984 KB Output is correct
4 Correct 15 ms 4992 KB Output is correct
5 Correct 12 ms 5088 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 11 ms 5120 KB Output is correct
8 Correct 12 ms 4984 KB Output is correct
9 Correct 10 ms 4984 KB Output is correct
10 Correct 12 ms 5116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4992 KB Output is correct
2 Correct 11 ms 4992 KB Output is correct
3 Correct 12 ms 4992 KB Output is correct
4 Correct 16 ms 5120 KB Output is correct
5 Correct 10 ms 4984 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 15 ms 4992 KB Output is correct
8 Correct 12 ms 4992 KB Output is correct
9 Correct 12 ms 4992 KB Output is correct
10 Correct 15 ms 4992 KB Output is correct
11 Correct 12 ms 4992 KB Output is correct
12 Correct 8 ms 4984 KB Output is correct
13 Correct 23 ms 5100 KB Output is correct
14 Correct 8 ms 896 KB Output is correct
15 Correct 15 ms 5112 KB Output is correct
16 Correct 42 ms 5240 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Partially correct 52 ms 5168 KB Partially correct - number of queries: 5480
19 Correct 9 ms 4992 KB Output is correct
20 Correct 21 ms 2688 KB Output is correct
21 Correct 25 ms 5112 KB Output is correct
22 Correct 11 ms 4992 KB Output is correct
23 Correct 9 ms 5120 KB Output is correct
24 Correct 9 ms 4992 KB Output is correct
25 Correct 30 ms 5120 KB Output is correct
26 Correct 33 ms 5112 KB Output is correct
27 Correct 10 ms 4992 KB Output is correct
28 Partially correct 45 ms 5240 KB Partially correct - number of queries: 5490
29 Correct 39 ms 5104 KB Output is correct
30 Partially correct 46 ms 5240 KB Partially correct - number of queries: 5511
31 Correct 8 ms 4984 KB Output is correct
32 Correct 16 ms 5112 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 14 ms 5148 KB Output is correct
35 Correct 13 ms 4992 KB Output is correct
36 Correct 18 ms 5112 KB Output is correct
37 Correct 10 ms 4984 KB Output is correct
38 Correct 7 ms 4964 KB Output is correct
39 Correct 30 ms 5144 KB Output is correct
40 Correct 40 ms 5240 KB Output is correct
41 Correct 31 ms 5112 KB Output is correct
42 Correct 31 ms 5112 KB Output is correct
43 Correct 28 ms 5116 KB Output is correct
44 Correct 27 ms 5112 KB Output is correct
45 Correct 24 ms 5112 KB Output is correct
46 Correct 7 ms 4984 KB Output is correct
47 Correct 30 ms 5112 KB Output is correct
48 Correct 34 ms 5112 KB Output is correct
49 Correct 12 ms 4992 KB Output is correct
50 Partially correct 50 ms 5368 KB Partially correct - number of queries: 5462
51 Correct 28 ms 5112 KB Output is correct
52 Correct 8 ms 5120 KB Output is correct
53 Correct 16 ms 5112 KB Output is correct
54 Correct 28 ms 5112 KB Output is correct
55 Correct 8 ms 4992 KB Output is correct
56 Partially correct 54 ms 5240 KB Partially correct - number of queries: 5474
57 Correct 45 ms 5112 KB Output is correct
58 Correct 40 ms 5396 KB Output is correct
59 Correct 38 ms 5240 KB Output is correct
60 Correct 32 ms 5112 KB Output is correct
61 Correct 17 ms 5112 KB Output is correct
62 Correct 10 ms 5120 KB Output is correct
63 Correct 15 ms 4984 KB Output is correct
64 Correct 12 ms 4992 KB Output is correct
65 Correct 16 ms 4992 KB Output is correct
66 Correct 20 ms 5112 KB Output is correct
67 Correct 18 ms 4992 KB Output is correct
68 Correct 8 ms 5120 KB Output is correct
69 Correct 20 ms 5112 KB Output is correct
70 Correct 16 ms 5112 KB Output is correct
71 Partially correct 46 ms 5244 KB Partially correct - number of queries: 5193
72 Correct 15 ms 5120 KB Output is correct
73 Partially correct 31 ms 5220 KB Partially correct - number of queries: 5123
74 Partially correct 52 ms 5112 KB Partially correct - number of queries: 5153
75 Correct 16 ms 5112 KB Output is correct
76 Correct 44 ms 5112 KB Output is correct
77 Partially correct 55 ms 5240 KB Partially correct - number of queries: 5435
78 Correct 20 ms 5112 KB Output is correct
79 Correct 32 ms 5112 KB Output is correct
80 Partially correct 62 ms 5240 KB Partially correct - number of queries: 5438
81 Partially correct 58 ms 5240 KB Partially correct - number of queries: 5407
82 Partially correct 38 ms 5232 KB Partially correct - number of queries: 5377
83 Correct 11 ms 5212 KB Output is correct
84 Correct 47 ms 5112 KB Output is correct
85 Partially correct 55 ms 5240 KB Partially correct - number of queries: 5384
86 Correct 15 ms 5120 KB Output is correct
87 Correct 15 ms 5120 KB Output is correct
88 Correct 19 ms 5112 KB Output is correct
89 Correct 15 ms 5120 KB Output is correct
90 Correct 13 ms 5112 KB Output is correct
91 Correct 15 ms 5112 KB Output is correct
92 Correct 17 ms 5112 KB Output is correct
93 Correct 16 ms 5120 KB Output is correct
94 Correct 16 ms 5120 KB Output is correct
95 Correct 18 ms 5112 KB Output is correct
96 Correct 16 ms 5024 KB Output is correct
97 Correct 14 ms 5112 KB Output is correct