Submission #590755

# Submission time Handle Problem Language Result Execution time Memory
590755 2022-07-06T10:15:07 Z alirezasamimi100 The Big Prize (IOI17_prize) C++17
100 / 100
49 ms 464 KB
#include "prize.h"
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int ans = -1, cnt = 0, mx = 0;

vector<int> vec[500],wh;
map<int,int> rv;

vector<int> doask(int i, int k = 0){
    vector<int> v;
    if(rv.count(i) && !k) v = vec[rv[i]];
    else v = ask(i);
    if(v[0] == 0 && v[1] == 0) ans = i;
    return v;
}

void solve(int l, int r, int x){
    if(ans != -1) return;
    int m1 = (l + r) >> 1, t = 0, m2 = m1 + 1, f;
    vector<int> v;
    while(m1 >= l || m2 < r){
        if(m1 >= l){
            v = doask(m1);
            m1--;
            if(v[0] + v[1] == mx){
                f = 0;
                break;
            }
            t++;
        }
        if(m2 < r){
            v = doask(m2);
            m2++;
            if(v[0] + v[1] == mx){
                f = 1;
                break;
            }
            t++;
        }
    }
    if(!f){
        if(l <= m1 && v[0] > cnt) solve(l, m1 + 1, v[1]);
        cnt += t;
        if(m2 < r && v[1] - x - t > 0) solve(m2, r, x);
    }else{
        if(l <= m1 && v[0] > cnt + t) solve(l, m1 + 1, v[1] + t);
        cnt += t;
        if(m2 < r && v[1] - x > 0) solve(m2, r, x);
    }
}
int find_best(int n) {
    queue<pair<int,int>> q;
    q.push({0,n});
    while((int)wh.size()<min(n,500) && !q.empty()){
        int l=q.front().first,r=q.front().second,m=(l+r)>>1;
        q.pop();
        if(!rv.count(m)){
            rv[m]=wh.size();
            wh.pb(m);
        }
        if(r-l>1){
            q.push({l,m});
            q.push({m,r});
        }
    }
    for(int i = 0; i < (int)wh.size(); i++){
        vec[i] = doask(wh[i], 1);
        if(vec[i][0] + vec[i][1] > mx) mx = vec[i][0] + vec[i][1];
    }
    int x = 0;
    while(n){
        vector<int> v = doask(n - 1);
        n--;
        if(v[0] + v[1] == mx) break;
        x++;
    }
    solve(0, n, x);
    return ans;
}

Compilation message

prize.cpp: In function 'void solve(int, int, int)':
prize.cpp:47:5: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |     if(!f){
      |     ^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 312 KB Output is correct
2 Correct 6 ms 308 KB Output is correct
3 Correct 5 ms 340 KB Output is correct
4 Correct 5 ms 332 KB Output is correct
5 Correct 4 ms 300 KB Output is correct
6 Correct 6 ms 340 KB Output is correct
7 Correct 4 ms 312 KB Output is correct
8 Correct 2 ms 308 KB Output is correct
9 Correct 5 ms 304 KB Output is correct
10 Correct 3 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 296 KB Output is correct
2 Correct 5 ms 284 KB Output is correct
3 Correct 6 ms 288 KB Output is correct
4 Correct 5 ms 312 KB Output is correct
5 Correct 5 ms 308 KB Output is correct
6 Correct 3 ms 352 KB Output is correct
7 Correct 4 ms 308 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 3 ms 336 KB Output is correct
10 Correct 5 ms 356 KB Output is correct
11 Correct 4 ms 336 KB Output is correct
12 Correct 4 ms 304 KB Output is correct
13 Correct 7 ms 308 KB Output is correct
14 Correct 9 ms 348 KB Output is correct
15 Correct 7 ms 304 KB Output is correct
16 Correct 35 ms 336 KB Output is correct
17 Correct 6 ms 356 KB Output is correct
18 Correct 38 ms 304 KB Output is correct
19 Correct 6 ms 340 KB Output is correct
20 Correct 7 ms 352 KB Output is correct
21 Correct 15 ms 336 KB Output is correct
22 Correct 7 ms 292 KB Output is correct
23 Correct 4 ms 304 KB Output is correct
24 Correct 5 ms 336 KB Output is correct
25 Correct 10 ms 360 KB Output is correct
26 Correct 25 ms 308 KB Output is correct
27 Correct 6 ms 336 KB Output is correct
28 Correct 16 ms 340 KB Output is correct
29 Correct 22 ms 296 KB Output is correct
30 Correct 19 ms 356 KB Output is correct
31 Correct 3 ms 344 KB Output is correct
32 Correct 10 ms 288 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 15 ms 336 KB Output is correct
35 Correct 3 ms 336 KB Output is correct
36 Correct 11 ms 340 KB Output is correct
37 Correct 3 ms 388 KB Output is correct
38 Correct 3 ms 352 KB Output is correct
39 Correct 23 ms 308 KB Output is correct
40 Correct 30 ms 336 KB Output is correct
41 Correct 20 ms 356 KB Output is correct
42 Correct 22 ms 336 KB Output is correct
43 Correct 22 ms 300 KB Output is correct
44 Correct 15 ms 304 KB Output is correct
45 Correct 14 ms 308 KB Output is correct
46 Correct 3 ms 328 KB Output is correct
47 Correct 16 ms 308 KB Output is correct
48 Correct 25 ms 336 KB Output is correct
49 Correct 7 ms 308 KB Output is correct
50 Correct 35 ms 360 KB Output is correct
51 Correct 16 ms 336 KB Output is correct
52 Correct 6 ms 304 KB Output is correct
53 Correct 3 ms 356 KB Output is correct
54 Correct 14 ms 296 KB Output is correct
55 Correct 5 ms 424 KB Output is correct
56 Correct 49 ms 336 KB Output is correct
57 Correct 14 ms 352 KB Output is correct
58 Correct 24 ms 312 KB Output is correct
59 Correct 24 ms 428 KB Output is correct
60 Correct 25 ms 308 KB Output is correct
61 Correct 4 ms 308 KB Output is correct
62 Correct 4 ms 336 KB Output is correct
63 Correct 6 ms 308 KB Output is correct
64 Correct 6 ms 352 KB Output is correct
65 Correct 4 ms 308 KB Output is correct
66 Correct 6 ms 336 KB Output is correct
67 Correct 4 ms 384 KB Output is correct
68 Correct 5 ms 312 KB Output is correct
69 Correct 9 ms 328 KB Output is correct
70 Correct 7 ms 336 KB Output is correct
71 Correct 38 ms 336 KB Output is correct
72 Correct 10 ms 464 KB Output is correct
73 Correct 36 ms 336 KB Output is correct
74 Correct 37 ms 336 KB Output is correct
75 Correct 6 ms 336 KB Output is correct
76 Correct 22 ms 356 KB Output is correct
77 Correct 34 ms 336 KB Output is correct
78 Correct 9 ms 336 KB Output is correct
79 Correct 18 ms 336 KB Output is correct
80 Correct 25 ms 336 KB Output is correct
81 Correct 33 ms 336 KB Output is correct
82 Correct 35 ms 336 KB Output is correct
83 Correct 5 ms 336 KB Output is correct
84 Correct 24 ms 356 KB Output is correct
85 Correct 43 ms 336 KB Output is correct
86 Correct 23 ms 336 KB Output is correct
87 Correct 6 ms 336 KB Output is correct
88 Correct 27 ms 336 KB Output is correct
89 Correct 20 ms 336 KB Output is correct
90 Correct 6 ms 336 KB Output is correct
91 Correct 14 ms 308 KB Output is correct
92 Correct 30 ms 336 KB Output is correct
93 Correct 23 ms 368 KB Output is correct
94 Correct 25 ms 336 KB Output is correct
95 Correct 22 ms 336 KB Output is correct
96 Correct 28 ms 336 KB Output is correct
97 Correct 16 ms 336 KB Output is correct