Submission #1057294

# Submission time Handle Problem Language Result Execution time Memory
1057294 2024-08-13T16:35:55 Z shenfe1 The Big Prize (IOI17_prize) C++17
20 / 100
39 ms 2788 KB
#include <bits/stdc++.h>
#include "prize.h"

using namespace std;

#define pb push_back
#define pii pair<int,int>
#define sz(s) (int)s.size()
#define F first
#define S second
#define all(v) v.begin(),v.end()

const int MAX=2e5+10;

bool use[MAX];
pii res[MAX];

pii cnt(int pos){
    if(use[pos])return res[pos];
    use[pos]=1;
    vector<int> v=ask(pos);
    return res[pos]={v[0],v[1]};
}

int sum(int pos){
    pii c=cnt(pos);
    return c.F+c.S;
}

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

int rnd(int l,int r){
    return rng()%(r-l+1)+l;
}

int cntMx;

int find_best(int n){
    cntMx=0;
    int L=1000;
    int r=0;
    for(int j=0;j<500;j++){
        // int j=rng()%n;
        cntMx=max(cntMx,sum(j));
        if(sum(j)==0)return j;
        if((n-sum(j))*1ll*(n-sum(j))+1>n)break;
        // r=i;
    }
    // cout<<r+1<<"\n";
    queue<pair<pii,pii>>  q;
    q.push({{0,n-1},{cntMx,0}});
    while(!q.empty()){
        int l=q.front().F.F,r=q.front().F.S,c=q.front().S.F,pl=q.front().S.S;
        q.pop();
        if(c==0)continue;
        if(c==r-l+1){
            for(int i=l;i<=r;i++){
                if(sum(i)==0)return i;
            }
            continue;
        }
        int tl=(l+r)/2,tr=(l+r)/2;
        while(tl>=l&&sum(tl)!=cntMx){
            if(sum(tl)==0)return tl;
            tl--;
        }
        while(tr<=r&&sum(tr)!=cntMx){
            if(sum(tr)==0)return tr;
            tr++;
        }
        int L=cnt(tl).F-pl;
        int R=c-L-max(0,tr-tl-1);
        // if(L+R!=c){
        //     cout<<l<<" "<<r<<" "<<L<<" "<<R<<"\n";
        // }
        if(l<=tl-1)q.push({{l,tl-1},{L,pl}});
        if(tr+1<=r)q.push({{tr+1,r},{R,cnt(tr).F}});
    }
    return -1;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:40:9: warning: unused variable 'L' [-Wunused-variable]
   40 |     int L=1000;
      |         ^
prize.cpp:41:9: warning: unused variable 'r' [-Wunused-variable]
   41 |     int r=0;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 356 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 440 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 440 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 444 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 2 ms 1112 KB Output is correct
12 Correct 3 ms 1112 KB Output is correct
13 Correct 3 ms 1112 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 18 ms 2040 KB Output is correct
16 Correct 11 ms 2136 KB Output is correct
17 Correct 19 ms 2136 KB Output is correct
18 Correct 9 ms 2136 KB Output is correct
19 Correct 14 ms 2136 KB Output is correct
20 Correct 10 ms 1112 KB Output is correct
21 Correct 9 ms 2136 KB Output is correct
22 Correct 18 ms 2136 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 2 ms 952 KB Output is correct
25 Correct 15 ms 1880 KB Output is correct
26 Correct 17 ms 1880 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 8 ms 1880 KB Output is correct
29 Correct 9 ms 1860 KB Output is correct
30 Correct 11 ms 2136 KB Output is correct
31 Correct 14 ms 2136 KB Output is correct
32 Correct 2 ms 1112 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 10 ms 2136 KB Output is correct
35 Correct 1 ms 856 KB Output is correct
36 Correct 17 ms 2392 KB Output is correct
37 Correct 2 ms 856 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 18 ms 2136 KB Output is correct
40 Correct 21 ms 2136 KB Output is correct
41 Correct 19 ms 2088 KB Output is correct
42 Correct 21 ms 2148 KB Output is correct
43 Correct 12 ms 2136 KB Output is correct
44 Correct 18 ms 2136 KB Output is correct
45 Correct 20 ms 2136 KB Output is correct
46 Correct 15 ms 2136 KB Output is correct
47 Correct 21 ms 2788 KB Output is correct
48 Correct 16 ms 2136 KB Output is correct
49 Correct 10 ms 2180 KB Output is correct
50 Correct 12 ms 2136 KB Output is correct
51 Correct 17 ms 2136 KB Output is correct
52 Correct 21 ms 2136 KB Output is correct
53 Correct 1 ms 600 KB Output is correct
54 Correct 21 ms 2136 KB Output is correct
55 Correct 17 ms 2136 KB Output is correct
56 Correct 20 ms 2392 KB Output is correct
57 Correct 16 ms 2136 KB Output is correct
58 Correct 21 ms 2136 KB Output is correct
59 Correct 24 ms 2392 KB Output is correct
60 Correct 10 ms 2392 KB Output is correct
61 Correct 1 ms 600 KB Output is correct
62 Correct 1 ms 600 KB Output is correct
63 Correct 1 ms 600 KB Output is correct
64 Correct 1 ms 600 KB Output is correct
65 Incorrect 39 ms 508 KB Incorrect
66 Halted 0 ms 0 KB -