Submission #577472

# Submission time Handle Problem Language Result Execution time Memory
577472 2022-06-14T19:02:53 Z definitelynotmee The Big Prize (IOI17_prize) C++
100 / 100
65 ms 11336 KB
#include<bits/stdc++.h>
#include "prize.h"
using namespace std;
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;

vector<vector<int>> resp;

vector<int> query(int id){
    if(resp[id][0] == -1){
        resp[id] = ask(id);
    }
    return resp[id];
}

int find_best(int n) {
	resp = vector<vector<int>>(n,{-1,-1});
    vector<int> start = ask(0);
    int ct = start[0]+start[1];
    if(ct == 0)
        return 0;
    
    vector<int> cand;
    bool flag = 0;

    auto solve =[&](int l, int r, int discl, int discr, auto solve)->void{
        if(r < l)
            return;
        
        if(discl + discr == ct)
            return;
        int m = (l+r)>>1;
        int mid = m;

        vector<int> ret = query(m);

        while(m <= r && ret[0]+ret[1] < ct){
            cand.push_back(m);
            m++;
            if(m <= r)
                ret = query(m);
        }

        if(ret[0]+ret[1] > ct){
            ct = ret[0]+ret[1];
            flag = 1;
            return;
        }

        if(m > r){
            int m = mid-1;
            if(m < l)
                return;
            ret = query(m);
            while(m >= l && ret[0]+ret[1] < ct){
                cand.push_back(m);
                m--;
                if(m >= l)
                    ret = query(m);
            }
            solve(l,m-1,discl,ret[1],solve);
            return;
        }
        solve(l,mid-1,discl,ret[1]+m-mid,solve);
        solve(m+1,r,ret[0],discr,solve);
    };
    do{
        cand.clear();
        flag = 0;
        solve(0,n-1,0,0,solve);
    } while(flag);
    
    for(int i : cand){
        vector<int> ret = query(i);
        if(ret[0]+ret[1] == 0){
            return i;
        }
    }

}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:24:30: warning: control reaches end of non-void function [-Wreturn-type]
   24 |     vector<int> start = ask(0);
      |                              ^
# Verdict Execution time Memory Grader output
1 Correct 12 ms 11216 KB Output is correct
2 Correct 11 ms 11240 KB Output is correct
3 Correct 11 ms 11156 KB Output is correct
4 Correct 14 ms 11252 KB Output is correct
5 Correct 12 ms 11152 KB Output is correct
6 Correct 14 ms 11168 KB Output is correct
7 Correct 11 ms 11248 KB Output is correct
8 Correct 13 ms 11232 KB Output is correct
9 Correct 11 ms 11204 KB Output is correct
10 Correct 11 ms 11216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 11208 KB Output is correct
2 Correct 11 ms 11264 KB Output is correct
3 Correct 11 ms 11176 KB Output is correct
4 Correct 11 ms 11168 KB Output is correct
5 Correct 16 ms 11172 KB Output is correct
6 Correct 14 ms 11208 KB Output is correct
7 Correct 11 ms 11204 KB Output is correct
8 Correct 11 ms 11264 KB Output is correct
9 Correct 11 ms 11140 KB Output is correct
10 Correct 12 ms 11212 KB Output is correct
11 Correct 14 ms 11208 KB Output is correct
12 Correct 12 ms 11268 KB Output is correct
13 Correct 16 ms 11164 KB Output is correct
14 Correct 9 ms 1360 KB Output is correct
15 Correct 44 ms 11252 KB Output is correct
16 Correct 37 ms 11156 KB Output is correct
17 Correct 62 ms 11260 KB Output is correct
18 Correct 51 ms 11216 KB Output is correct
19 Correct 35 ms 11252 KB Output is correct
20 Correct 26 ms 5712 KB Output is correct
21 Correct 29 ms 11260 KB Output is correct
22 Correct 27 ms 11252 KB Output is correct
23 Correct 13 ms 11248 KB Output is correct
24 Correct 14 ms 11168 KB Output is correct
25 Correct 27 ms 11268 KB Output is correct
26 Correct 38 ms 11208 KB Output is correct
27 Correct 12 ms 11172 KB Output is correct
28 Correct 29 ms 11268 KB Output is correct
29 Correct 46 ms 11168 KB Output is correct
30 Correct 51 ms 11216 KB Output is correct
31 Correct 43 ms 11216 KB Output is correct
32 Correct 16 ms 11216 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 45 ms 11256 KB Output is correct
35 Correct 15 ms 11140 KB Output is correct
36 Correct 47 ms 11256 KB Output is correct
37 Correct 14 ms 11208 KB Output is correct
38 Correct 12 ms 11216 KB Output is correct
39 Correct 44 ms 11252 KB Output is correct
40 Correct 38 ms 11168 KB Output is correct
41 Correct 55 ms 11252 KB Output is correct
42 Correct 56 ms 11252 KB Output is correct
43 Correct 44 ms 11164 KB Output is correct
44 Correct 50 ms 11252 KB Output is correct
45 Correct 45 ms 11256 KB Output is correct
46 Correct 56 ms 11208 KB Output is correct
47 Correct 29 ms 11268 KB Output is correct
48 Correct 52 ms 11336 KB Output is correct
49 Correct 43 ms 11252 KB Output is correct
50 Correct 60 ms 11216 KB Output is correct
51 Correct 52 ms 11252 KB Output is correct
52 Correct 65 ms 11336 KB Output is correct
53 Correct 13 ms 11216 KB Output is correct
54 Correct 49 ms 11168 KB Output is correct
55 Correct 47 ms 11176 KB Output is correct
56 Correct 28 ms 11264 KB Output is correct
57 Correct 45 ms 11216 KB Output is correct
58 Correct 42 ms 11256 KB Output is correct
59 Correct 50 ms 11252 KB Output is correct
60 Correct 36 ms 11272 KB Output is correct
61 Correct 14 ms 11176 KB Output is correct
62 Correct 12 ms 11276 KB Output is correct
63 Correct 13 ms 11168 KB Output is correct
64 Correct 11 ms 11216 KB Output is correct
65 Correct 11 ms 11252 KB Output is correct
66 Correct 17 ms 11176 KB Output is correct
67 Correct 14 ms 11164 KB Output is correct
68 Correct 14 ms 11208 KB Output is correct
69 Correct 13 ms 11164 KB Output is correct
70 Correct 16 ms 11208 KB Output is correct
71 Correct 55 ms 11272 KB Output is correct
72 Correct 12 ms 11268 KB Output is correct
73 Correct 51 ms 11260 KB Output is correct
74 Correct 52 ms 11256 KB Output is correct
75 Correct 14 ms 11216 KB Output is correct
76 Correct 37 ms 11216 KB Output is correct
77 Correct 45 ms 11224 KB Output is correct
78 Correct 13 ms 11268 KB Output is correct
79 Correct 22 ms 11192 KB Output is correct
80 Correct 44 ms 11252 KB Output is correct
81 Correct 52 ms 11216 KB Output is correct
82 Correct 28 ms 11268 KB Output is correct
83 Correct 11 ms 11268 KB Output is correct
84 Correct 40 ms 11260 KB Output is correct
85 Correct 53 ms 11216 KB Output is correct
86 Correct 18 ms 11272 KB Output is correct
87 Correct 12 ms 11172 KB Output is correct
88 Correct 14 ms 11216 KB Output is correct
89 Correct 14 ms 11280 KB Output is correct
90 Correct 12 ms 11272 KB Output is correct
91 Correct 16 ms 11216 KB Output is correct
92 Correct 18 ms 11224 KB Output is correct
93 Correct 14 ms 11216 KB Output is correct
94 Correct 14 ms 11216 KB Output is correct
95 Correct 14 ms 11216 KB Output is correct
96 Correct 13 ms 11216 KB Output is correct
97 Correct 11 ms 11216 KB Output is correct