Submission #344353

# Submission time Handle Problem Language Result Execution time Memory
344353 2021-01-05T14:18:12 Z 79brue The Big Prize (IOI17_prize) C++14
100 / 100
104 ms 7776 KB
#include <bits/stdc++.h>
#include "prize.h"

using namespace std;

typedef long long ll;

struct dat{
    int l, r, lx, rx;
    dat(){}
    dat(int l, int r, int lx, int rx): l(l), r(r), lx(lx), rx(rx){}
};

vector<int> vec;
vector<int> chk[200002];
int connect[200002];
int queryCount;

vector<int> my_ask(int x){
    if(chk[x].size() == 2) return chk[x];
    queryCount++;
    return chk[x] = ask(x);
}

int find_best(int n){
    for(int i=1; i<=200000; i++){
        int tmp = int(floor(sqrt(i-1)) + 1e-8);
        connect[i] = connect[tmp] + i;
    }

    for(int i=0; i<n; i++) vec.push_back(i);
    while((int)vec.size() > 1){
        queue<dat> que;
        int k = (int)vec.size();

        int sum = 0, lim = 0;
        for(int i=0; connect[i+1] + (i+1)*(i+1) + 1 <= k; i++) lim = connect[i+1];
        vector<int> randomVec = vec;
        random_shuffle(randomVec.begin(), randomVec.end());
        sort(randomVec.begin(), randomVec.end(), [&](auto x, auto y){
            if(chk[x].size() == 2 && chk[y].size() != 2) return x<y;
            if(chk[x].size() != 2 && chk[y].size() == 2) return x>y;
            return false;
        });
        for(int i=0; i<=lim && i<k; i++){
            auto tVec = my_ask(randomVec[i]);
            sum = max(sum, tVec[0] + tVec[1]);
            if(sum >= lim) break;
        }
        que.push(dat(0, k-1, 0, 0));

        vector<int> newVec;

        while(!que.empty()){
            dat tmp = que.front(); que.pop();
            int cnt = tmp.r - tmp.l + 1 - (sum - tmp.lx - tmp.rx);
            if(cnt == 0){
                for(int x=tmp.l; x<=tmp.r; x++){
                    newVec.push_back(vec[x]);
                }
                continue;
            }

            int mid = (tmp.l + tmp.r) / 2;
            int midL = mid, midR = mid;
            while(mid <= tmp.r){
                auto tVec = my_ask(vec[mid]);
                if(tVec[0] + tVec[1] == sum) break;
                midR = mid;
                newVec.push_back(vec[mid++]);
            }
            if(mid > tmp.r){
                mid = (tmp.l + tmp.r) / 2;
                while(mid >= tmp.l){
                    auto tVec = my_ask(vec[mid]);
                    if(tVec[0] + tVec[1] == sum) break;
                    midL = mid;
                    newVec.push_back(vec[mid--]);
                }
            }
            if(mid < tmp.l) continue;

            auto tVec = my_ask(vec[mid]);
            assert(tVec[0] + tVec[1] == sum);
            if(tVec[0] != tmp.lx){
                int rightCount = tVec[1];
                if(mid == midR + 1) rightCount += (midR - (tmp.l + tmp.r) / 2 + 1);
                que.push(dat(tmp.l, midL-1, tmp.lx, rightCount));
            }
            if(midR+1 <= tmp.r && tVec[1] != tmp.rx) que.push(dat(midR+1, tmp.r, tVec[0], tmp.rx));
        }

        vec = newVec;
        sort(vec.begin(), vec.end());
    }
    return vec[0];
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 7520 KB Output is correct
2 Correct 29 ms 7520 KB Output is correct
3 Correct 30 ms 7648 KB Output is correct
4 Correct 32 ms 7648 KB Output is correct
5 Correct 31 ms 7520 KB Output is correct
6 Correct 28 ms 7520 KB Output is correct
7 Correct 29 ms 7520 KB Output is correct
8 Correct 30 ms 7520 KB Output is correct
9 Correct 31 ms 7520 KB Output is correct
10 Correct 31 ms 7648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 7520 KB Output is correct
2 Correct 29 ms 7520 KB Output is correct
3 Correct 32 ms 7648 KB Output is correct
4 Correct 41 ms 7520 KB Output is correct
5 Correct 30 ms 7520 KB Output is correct
6 Correct 31 ms 7520 KB Output is correct
7 Correct 30 ms 7520 KB Output is correct
8 Correct 32 ms 7520 KB Output is correct
9 Correct 30 ms 7648 KB Output is correct
10 Correct 31 ms 7520 KB Output is correct
11 Correct 43 ms 7520 KB Output is correct
12 Correct 38 ms 7520 KB Output is correct
13 Correct 32 ms 7520 KB Output is correct
14 Correct 19 ms 5996 KB Output is correct
15 Correct 68 ms 7520 KB Output is correct
16 Correct 66 ms 7520 KB Output is correct
17 Correct 67 ms 7520 KB Output is correct
18 Correct 65 ms 7556 KB Output is correct
19 Correct 53 ms 7596 KB Output is correct
20 Correct 45 ms 6756 KB Output is correct
21 Correct 82 ms 7648 KB Output is correct
22 Correct 60 ms 7520 KB Output is correct
23 Correct 35 ms 7520 KB Output is correct
24 Correct 38 ms 7520 KB Output is correct
25 Correct 56 ms 7520 KB Output is correct
26 Correct 69 ms 7520 KB Output is correct
27 Correct 30 ms 7520 KB Output is correct
28 Correct 64 ms 7556 KB Output is correct
29 Correct 57 ms 7648 KB Output is correct
30 Correct 67 ms 7676 KB Output is correct
31 Correct 52 ms 7620 KB Output is correct
32 Correct 34 ms 7520 KB Output is correct
33 Correct 6 ms 5740 KB Output is correct
34 Correct 71 ms 7648 KB Output is correct
35 Correct 34 ms 7520 KB Output is correct
36 Correct 72 ms 7520 KB Output is correct
37 Correct 36 ms 7520 KB Output is correct
38 Correct 39 ms 7776 KB Output is correct
39 Correct 69 ms 7648 KB Output is correct
40 Correct 68 ms 7520 KB Output is correct
41 Correct 68 ms 7520 KB Output is correct
42 Correct 64 ms 7520 KB Output is correct
43 Correct 72 ms 7556 KB Output is correct
44 Correct 53 ms 7664 KB Output is correct
45 Correct 67 ms 7684 KB Output is correct
46 Correct 60 ms 7520 KB Output is correct
47 Correct 63 ms 7520 KB Output is correct
48 Correct 53 ms 7668 KB Output is correct
49 Correct 66 ms 7648 KB Output is correct
50 Correct 63 ms 7572 KB Output is correct
51 Correct 67 ms 7520 KB Output is correct
52 Correct 71 ms 7520 KB Output is correct
53 Correct 31 ms 7520 KB Output is correct
54 Correct 71 ms 7640 KB Output is correct
55 Correct 73 ms 7648 KB Output is correct
56 Correct 67 ms 7556 KB Output is correct
57 Correct 70 ms 7556 KB Output is correct
58 Correct 75 ms 7648 KB Output is correct
59 Correct 65 ms 7520 KB Output is correct
60 Correct 63 ms 7520 KB Output is correct
61 Correct 35 ms 7648 KB Output is correct
62 Correct 30 ms 7520 KB Output is correct
63 Correct 42 ms 7520 KB Output is correct
64 Correct 31 ms 7520 KB Output is correct
65 Correct 31 ms 7520 KB Output is correct
66 Correct 28 ms 7496 KB Output is correct
67 Correct 37 ms 7520 KB Output is correct
68 Correct 31 ms 7520 KB Output is correct
69 Correct 30 ms 7520 KB Output is correct
70 Correct 32 ms 7520 KB Output is correct
71 Correct 51 ms 7572 KB Output is correct
72 Correct 46 ms 7520 KB Output is correct
73 Correct 90 ms 7520 KB Output is correct
74 Correct 81 ms 7668 KB Output is correct
75 Correct 31 ms 7520 KB Output is correct
76 Correct 59 ms 7520 KB Output is correct
77 Correct 69 ms 7520 KB Output is correct
78 Correct 36 ms 7520 KB Output is correct
79 Correct 64 ms 7520 KB Output is correct
80 Correct 71 ms 7648 KB Output is correct
81 Correct 54 ms 7652 KB Output is correct
82 Correct 89 ms 7648 KB Output is correct
83 Correct 33 ms 7520 KB Output is correct
84 Correct 76 ms 7648 KB Output is correct
85 Correct 63 ms 7520 KB Output is correct
86 Correct 43 ms 7520 KB Output is correct
87 Correct 37 ms 7520 KB Output is correct
88 Correct 61 ms 7520 KB Output is correct
89 Correct 65 ms 7556 KB Output is correct
90 Correct 32 ms 7520 KB Output is correct
91 Correct 53 ms 7520 KB Output is correct
92 Correct 60 ms 7520 KB Output is correct
93 Correct 62 ms 7556 KB Output is correct
94 Correct 84 ms 7648 KB Output is correct
95 Correct 63 ms 7556 KB Output is correct
96 Correct 104 ms 7520 KB Output is correct
97 Correct 70 ms 7520 KB Output is correct