Submission #131495

# Submission time Handle Problem Language Result Execution time Memory
131495 2019-07-17T08:17:49 Z 20160161simone The Big Prize (IOI17_prize) C++14
20 / 100
78 ms 2168 KB
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include "prize.h"
using namespace std;
vector<int> res;
#define Maxn 200010
bool flag[Maxn];
int ans[Maxn][2];
int maxv=0,pos;
int answer;
void Ask(int x){
    if(flag[x])return;
    flag[x]=true;
    res=ask(x);
    ans[x][0]=res[0];ans[x][1]=res[1];
}
void solve(int l,int r,int ed,int val){
    if(l==r){
        Ask(l);
        if(ans[l][0]==0&&ans[l][1]==0)answer=l;
        return;
    }
    int mid=(l+r)>>1;
    if(ed==-1){
        solve(l,mid,ed,mid-l+1);
        solve(mid+1,r,ed,r-mid);
        return;
    }
    if(ed<=mid){
        if(val-(r-mid))solve(l,mid,ed,val-(r-mid));
        solve(mid+1,r,-1,r-mid);
        return;
    }
    int tmp=-1;
    for(int i=mid;i>=l;--i){
        Ask(i);
        if(ans[i][0]+ans[i][1]==maxv){
            tmp=i;
            break;
        }
    }
    if(tmp==-1){
        solve(l,mid,-1,mid-l+1);
        if(val-(mid-l+1))solve(mid+1,r,ed,val-(mid-l+1));
        return;
    }
    int now=ans[ed][0]-ans[tmp][0]-(mid-tmp)+r-ed;
    if(now)solve(mid+1,r,ed,now);
    now=val-now;
    if(now)solve(l,mid,tmp,now);
}
int find_best(int n){
    srand(time(NULL));
    for(register int i=1;i<=100;++i){
        int x=1ll*rand()*rand()%n;
        Ask(x);
        maxv=max(maxv,ans[x][0]+ans[x][1]);
    }
    int last;
    for(register int i=n-1;i>=0;--i){
        Ask(i);
        if(ans[i][0]==0&&ans[i][1]==0)return i;
        if(ans[i][0]+ans[i][1]==maxv){
            last=i;
            break;
        }
    }
    solve(0,n-1,last,ans[last][0]+ans[last][1]);
    return answer;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:64:9: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int last;
         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 908 KB Output is correct
2 Correct 4 ms 888 KB Output is correct
3 Correct 3 ms 808 KB Output is correct
4 Correct 4 ms 808 KB Output is correct
5 Correct 4 ms 888 KB Output is correct
6 Correct 4 ms 888 KB Output is correct
7 Correct 4 ms 888 KB Output is correct
8 Correct 5 ms 888 KB Output is correct
9 Correct 3 ms 856 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 888 KB Output is correct
2 Correct 4 ms 760 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
4 Correct 3 ms 868 KB Output is correct
5 Correct 3 ms 888 KB Output is correct
6 Correct 3 ms 864 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 4 ms 760 KB Output is correct
9 Correct 4 ms 888 KB Output is correct
10 Correct 3 ms 924 KB Output is correct
11 Correct 8 ms 1272 KB Output is correct
12 Correct 9 ms 1332 KB Output is correct
13 Correct 9 ms 1332 KB Output is correct
14 Correct 14 ms 504 KB Output is correct
15 Correct 27 ms 2084 KB Output is correct
16 Correct 48 ms 2064 KB Output is correct
17 Correct 49 ms 2008 KB Output is correct
18 Correct 49 ms 2068 KB Output is correct
19 Correct 37 ms 1964 KB Output is correct
20 Correct 36 ms 1180 KB Output is correct
21 Correct 53 ms 1952 KB Output is correct
22 Correct 44 ms 2040 KB Output is correct
23 Correct 5 ms 888 KB Output is correct
24 Correct 6 ms 1204 KB Output is correct
25 Correct 33 ms 1980 KB Output is correct
26 Correct 36 ms 2000 KB Output is correct
27 Correct 5 ms 952 KB Output is correct
28 Correct 52 ms 1912 KB Output is correct
29 Correct 42 ms 1844 KB Output is correct
30 Correct 37 ms 2168 KB Output is correct
31 Correct 47 ms 2000 KB Output is correct
32 Correct 8 ms 1208 KB Output is correct
33 Correct 2 ms 248 KB Output is correct
34 Correct 52 ms 2020 KB Output is correct
35 Correct 4 ms 1100 KB Output is correct
36 Correct 48 ms 1960 KB Output is correct
37 Correct 5 ms 1208 KB Output is correct
38 Correct 5 ms 936 KB Output is correct
39 Correct 50 ms 2100 KB Output is correct
40 Correct 35 ms 2028 KB Output is correct
41 Correct 31 ms 2032 KB Output is correct
42 Correct 47 ms 2028 KB Output is correct
43 Correct 47 ms 2040 KB Output is correct
44 Correct 50 ms 1980 KB Output is correct
45 Correct 43 ms 1976 KB Output is correct
46 Correct 39 ms 2048 KB Output is correct
47 Correct 35 ms 1972 KB Output is correct
48 Correct 35 ms 2112 KB Output is correct
49 Correct 46 ms 2096 KB Output is correct
50 Correct 55 ms 1992 KB Output is correct
51 Correct 48 ms 1960 KB Output is correct
52 Correct 37 ms 1984 KB Output is correct
53 Correct 6 ms 1016 KB Output is correct
54 Correct 28 ms 2100 KB Output is correct
55 Correct 50 ms 2120 KB Output is correct
56 Correct 30 ms 2040 KB Output is correct
57 Correct 47 ms 2040 KB Output is correct
58 Correct 29 ms 2012 KB Output is correct
59 Correct 31 ms 2096 KB Output is correct
60 Correct 53 ms 2040 KB Output is correct
61 Correct 5 ms 1016 KB Output is correct
62 Correct 4 ms 896 KB Output is correct
63 Correct 5 ms 888 KB Output is correct
64 Correct 5 ms 1016 KB Output is correct
65 Correct 4 ms 760 KB Output is correct
66 Correct 4 ms 760 KB Output is correct
67 Correct 10 ms 760 KB Output is correct
68 Correct 8 ms 888 KB Output is correct
69 Correct 4 ms 760 KB Output is correct
70 Correct 6 ms 760 KB Output is correct
71 Correct 60 ms 2040 KB Output is correct
72 Correct 10 ms 1272 KB Output is correct
73 Correct 49 ms 1960 KB Output is correct
74 Correct 57 ms 2100 KB Output is correct
75 Correct 5 ms 948 KB Output is correct
76 Correct 51 ms 2128 KB Output is correct
77 Correct 61 ms 2040 KB Output is correct
78 Correct 9 ms 1400 KB Output is correct
79 Correct 29 ms 1932 KB Output is correct
80 Correct 35 ms 2160 KB Output is correct
81 Correct 37 ms 1988 KB Output is correct
82 Correct 38 ms 1984 KB Output is correct
83 Correct 19 ms 960 KB Output is correct
84 Correct 42 ms 2068 KB Output is correct
85 Correct 51 ms 1944 KB Output is correct
86 Incorrect 78 ms 1016 KB Incorrect
87 Halted 0 ms 0 KB -