Submission #577459

# Submission time Handle Problem Language Result Execution time Memory
577459 2022-06-14T18:32:51 Z Theo830 The Big Prize (IOI17_prize) C++17
100 / 100
82 ms 47604 KB
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define ull unsigned int
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<ll> distr;
ll rnd(ll a, ll b){return distr(rng)%(b-a+1)+a;}
//int find_best(int n);
//std::vector<int> ask(int i);
#include "prize.h"
ll maxi = 0;
vector<int> ans[2000005];
vector<int> Ask(ll x){
    if(ans[x].empty()){
        ans[x] = ask(x);
    }
    return ans[x];
}
ll solve(ll l,ll r,ll L,ll R){
    if(l > r){
        return -1;
    }
    ll mid = (l+r)/2;
    vector<int>res = Ask(mid);
    if(res[0] == 0 && res[1] == 0){
        return mid;
    }
    if(l == r){
        return -1;
    }
    ll ans = -1;
    ll left = mid,right = mid;
    ll cur = 0;
    while(res[0] + res[1] < maxi){
        if(cur == 0){
            left--;
            if(left >= l){
                res = Ask(left);
                if(res[0] == 0 && res[1] == 0){
                    return left;
                }
            }
        }
        else{
            right++;
            if(right <= r){
                res = Ask(right);
                if(res[0] == 0 && res[1] == 0){
                    return right;
                }
            }
        }
        if(left < l && right > r){
            break;
        }
        cur ^= 1;
    }
    if((res[0] + res[1]) == maxi){
        if(res[0] != L){
            ans = solve(l,left - 1,L,res[1]);
        }
        if(res[1] != R && ans == -1){
            ans = solve(right + 1,r,res[0],R);
        }
    }
    return ans;
}
int find_best(int n){
    ll k = 500;
    while(k--){
        vector<int> res = ask(rnd(0,n-1));
        maxi = max(maxi,res[0] + res[1]);
        if(res[0] + res[1] > 30){
            break;
        }
    }
    return solve(0,n-1,0,0);
}
/*
static const int max_q = 10000;
static int n;
static int query_count = 0;
vector<int> g;
static vector<vector<int> > rank_count;

vector<int> ask(int i) {
    //cout<<i<<endl;
    query_count++;
    if(query_count > max_q) {
        cerr << "Query limit exceeded" << endl;
        exit(0);
    }

    if(i < 0 || i >= n) {
        cerr << "Bad index: " << i << endl;
        exit(0);
    }

    vector<int> res(2);
    res[0] = rank_count[g[i] - 1][i + 1];
    res[1] = rank_count[g[i] - 1][n] - res[0];
    return res;
}

int main() {
    n = 1 + 2 + 5 + 30 + 200000;
    g.pb(1);
    g.pb(2);
    g.pb(2);
    f(k,0,5){
        g.pb(3);
    }
    f(k,0,30){
        g.pb(4);
    }
    f(k,0,200000){
        g.pb(5);
    }
    random_shuffle(all(g));
    int max_rank = *max_element(g.begin(), g.end());

    rank_count.resize(max_rank + 1, vector<int>(n + 1, 0));
    for(int r = 0; r <= max_rank; r++) {
        for(int i = 1; i <= n; i++) {
            rank_count[r][i] = rank_count[r][i - 1];
            if(g[i - 1] == r)
              rank_count[r][i]++;
        }
    }

    for(int i = 0; i <= n; i++)
        for(int r = 1; r <= max_rank; r++)
            rank_count[r][i] += rank_count[r - 1][i];
    int res = find_best(n);
    assert(g[res] == 1);
    cout << res << endl << "Query count: " << query_count << endl;

    return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 33 ms 47164 KB Output is correct
2 Correct 31 ms 47144 KB Output is correct
3 Correct 27 ms 47236 KB Output is correct
4 Correct 26 ms 47140 KB Output is correct
5 Correct 29 ms 47184 KB Output is correct
6 Correct 34 ms 47224 KB Output is correct
7 Correct 35 ms 47188 KB Output is correct
8 Correct 27 ms 47184 KB Output is correct
9 Correct 31 ms 47144 KB Output is correct
10 Correct 28 ms 47228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 47172 KB Output is correct
2 Correct 27 ms 47184 KB Output is correct
3 Correct 28 ms 47184 KB Output is correct
4 Correct 29 ms 47120 KB Output is correct
5 Correct 29 ms 47184 KB Output is correct
6 Correct 29 ms 47216 KB Output is correct
7 Correct 29 ms 47260 KB Output is correct
8 Correct 29 ms 47184 KB Output is correct
9 Correct 28 ms 47184 KB Output is correct
10 Correct 29 ms 47180 KB Output is correct
11 Correct 26 ms 47184 KB Output is correct
12 Correct 25 ms 47268 KB Output is correct
13 Correct 32 ms 47288 KB Output is correct
14 Correct 25 ms 47164 KB Output is correct
15 Correct 31 ms 47184 KB Output is correct
16 Correct 63 ms 47368 KB Output is correct
17 Correct 24 ms 47176 KB Output is correct
18 Correct 69 ms 47572 KB Output is correct
19 Correct 25 ms 47176 KB Output is correct
20 Correct 34 ms 47220 KB Output is correct
21 Correct 45 ms 47252 KB Output is correct
22 Correct 28 ms 47184 KB Output is correct
23 Correct 30 ms 47264 KB Output is correct
24 Correct 26 ms 47184 KB Output is correct
25 Correct 44 ms 47272 KB Output is correct
26 Correct 45 ms 47280 KB Output is correct
27 Correct 28 ms 47264 KB Output is correct
28 Correct 60 ms 47308 KB Output is correct
29 Correct 49 ms 47316 KB Output is correct
30 Correct 44 ms 47388 KB Output is correct
31 Correct 25 ms 47256 KB Output is correct
32 Correct 27 ms 47264 KB Output is correct
33 Correct 26 ms 47200 KB Output is correct
34 Correct 35 ms 47176 KB Output is correct
35 Correct 27 ms 47184 KB Output is correct
36 Correct 33 ms 47260 KB Output is correct
37 Correct 27 ms 47212 KB Output is correct
38 Correct 31 ms 47224 KB Output is correct
39 Correct 50 ms 47260 KB Output is correct
40 Correct 63 ms 47356 KB Output is correct
41 Correct 42 ms 47332 KB Output is correct
42 Correct 45 ms 47328 KB Output is correct
43 Correct 60 ms 47304 KB Output is correct
44 Correct 40 ms 47304 KB Output is correct
45 Correct 36 ms 47344 KB Output is correct
46 Correct 24 ms 47220 KB Output is correct
47 Correct 37 ms 47300 KB Output is correct
48 Correct 58 ms 47328 KB Output is correct
49 Correct 27 ms 47152 KB Output is correct
50 Correct 64 ms 47424 KB Output is correct
51 Correct 37 ms 47304 KB Output is correct
52 Correct 27 ms 47264 KB Output is correct
53 Correct 31 ms 47252 KB Output is correct
54 Correct 41 ms 47416 KB Output is correct
55 Correct 26 ms 47176 KB Output is correct
56 Correct 72 ms 47316 KB Output is correct
57 Correct 57 ms 47280 KB Output is correct
58 Correct 38 ms 47412 KB Output is correct
59 Correct 47 ms 47304 KB Output is correct
60 Correct 49 ms 47312 KB Output is correct
61 Correct 32 ms 47184 KB Output is correct
62 Correct 30 ms 47168 KB Output is correct
63 Correct 29 ms 47248 KB Output is correct
64 Correct 29 ms 47260 KB Output is correct
65 Correct 26 ms 47172 KB Output is correct
66 Correct 31 ms 47240 KB Output is correct
67 Correct 33 ms 47344 KB Output is correct
68 Correct 32 ms 47164 KB Output is correct
69 Correct 27 ms 47188 KB Output is correct
70 Correct 26 ms 47184 KB Output is correct
71 Correct 68 ms 47336 KB Output is correct
72 Correct 29 ms 47200 KB Output is correct
73 Correct 50 ms 47396 KB Output is correct
74 Correct 63 ms 47376 KB Output is correct
75 Correct 35 ms 47252 KB Output is correct
76 Correct 55 ms 47356 KB Output is correct
77 Correct 80 ms 47304 KB Output is correct
78 Correct 29 ms 47152 KB Output is correct
79 Correct 52 ms 47260 KB Output is correct
80 Correct 61 ms 47296 KB Output is correct
81 Correct 74 ms 47472 KB Output is correct
82 Correct 76 ms 47384 KB Output is correct
83 Correct 34 ms 47228 KB Output is correct
84 Correct 82 ms 47364 KB Output is correct
85 Correct 58 ms 47308 KB Output is correct
86 Correct 37 ms 47272 KB Output is correct
87 Correct 32 ms 47248 KB Output is correct
88 Correct 48 ms 47316 KB Output is correct
89 Correct 44 ms 47412 KB Output is correct
90 Correct 27 ms 47272 KB Output is correct
91 Correct 39 ms 47396 KB Output is correct
92 Correct 41 ms 47272 KB Output is correct
93 Correct 71 ms 47360 KB Output is correct
94 Correct 75 ms 47308 KB Output is correct
95 Correct 67 ms 47604 KB Output is correct
96 Correct 72 ms 47372 KB Output is correct
97 Correct 74 ms 47360 KB Output is correct