#include "prize.h"
#include <bits/stdc++.h>
#define sz(x) (int)(x.size())
#define debug printf
#define lp(i,a,b) for(int i = a ; i < b; i++)
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pii pair<int,int>
#define ll long long
#define all(x) x.begin(),x.end()
const int MAX = 2e5+10 ;
using namespace std ;
int cte ;
int soma[MAX] ;
int record[MAX][2] ;
bool went[MAX] ;
bool isLollipop(int i) { return soma[i] == cte ; }
bool isDiamond(int i) { return soma[i] == 0; }
void pergunta(int i)
{
if(went[i]) return ;
went[i] = true ;
vector<int> a = ask(i) ;
record[i][0] = a[0] ;
record[i][1]= a[1] ;
soma[i] = a[0] + a[1] ;
}
int find_best(int n)
{
if( n <= 5000 )
{
for(int i = 0 ; i < n ; i++ )
{
pergunta(i) ;
if( isDiamond(i) ) return i ;
}
}
else
{
vector<int> vec(n, 0) ;
iota(all(vec) , 0 ) ;
srand(time(0)) ;
random_shuffle(all(vec)) ;
set<int> s ;
for(int i = 0 ; i < 450 ; i++ )
{
pergunta( vec[i] ) ;
s.insert( soma[ vec[i] ] ) ;
if( isDiamond(vec[i]) ) return vec[i] ;
if(sz(vec) == 5 || soma[ vec[i] ] >= 450 ) break ;
}
cte = *prev( s.end() ) ;
}
vector<pii> fila(1);
for(int i = 0 ; i < n ; i++ )
{
pergunta(i) ;
if( isDiamond(i) ) return i ;
if( !isLollipop(i) ) continue ;
fila[0].ff = i+1 ;
break ;
}
for(int i= n-1 ; i >= 0 ; i-- )
{
pergunta(i) ;
if(isDiamond(i)) return i ;
if( !isLollipop(i) ) continue ;
fila[0].ss = i-1 ;
break ;
}
int ptr = 0 ;
while( ptr < sz(fila) )
{
int l = fila[ptr].ff ;
int r = fila[ptr].ss ;
ptr++ ;
int mid = (l+r)>>1 ;
pergunta(mid);
//Calculate left interval
int newR = mid ;
while( true )
{
pergunta(newR) ;
if(isDiamond(newR)) return newR ;
if( !isLollipop(newR) ) newR-- ;
else break ;
}
newR-- ;
if( l <= newR && (record[l-1][1] - record[newR+1][1] > 0 ) )
{
fila.push_back( make_pair(l,newR) ) ;
}
//Calculate right interval
int newL = mid ;
while( true )
{
pergunta(newL) ;
if( isDiamond(newL) ) return newL ;
if(!isLollipop(newL)) newL++ ;
else break ;
}
newL++ ;
if( newL <= r && (record[newL-1][1] - record[r+1][1]) > 0 )
fila.push_back( make_pair(newL, r) ) ;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
3200 KB |
Output is correct |
2 |
Correct |
11 ms |
3064 KB |
Output is correct |
3 |
Correct |
10 ms |
3072 KB |
Output is correct |
4 |
Correct |
12 ms |
3064 KB |
Output is correct |
5 |
Correct |
11 ms |
3072 KB |
Output is correct |
6 |
Correct |
10 ms |
3064 KB |
Output is correct |
7 |
Correct |
9 ms |
3076 KB |
Output is correct |
8 |
Correct |
13 ms |
3064 KB |
Output is correct |
9 |
Correct |
10 ms |
3064 KB |
Output is correct |
10 |
Correct |
10 ms |
3072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
3072 KB |
Output is correct |
2 |
Correct |
10 ms |
3064 KB |
Output is correct |
3 |
Correct |
9 ms |
3156 KB |
Output is correct |
4 |
Correct |
10 ms |
3236 KB |
Output is correct |
5 |
Correct |
11 ms |
3064 KB |
Output is correct |
6 |
Correct |
11 ms |
3056 KB |
Output is correct |
7 |
Correct |
11 ms |
3064 KB |
Output is correct |
8 |
Correct |
11 ms |
3064 KB |
Output is correct |
9 |
Correct |
11 ms |
3072 KB |
Output is correct |
10 |
Correct |
10 ms |
3064 KB |
Output is correct |
11 |
Correct |
17 ms |
3064 KB |
Output is correct |
12 |
Correct |
19 ms |
3092 KB |
Output is correct |
13 |
Correct |
17 ms |
3064 KB |
Output is correct |
14 |
Correct |
20 ms |
640 KB |
Output is correct |
15 |
Correct |
62 ms |
3064 KB |
Output is correct |
16 |
Correct |
56 ms |
2928 KB |
Output is correct |
17 |
Correct |
31 ms |
2980 KB |
Output is correct |
18 |
Correct |
51 ms |
2920 KB |
Output is correct |
19 |
Correct |
35 ms |
3064 KB |
Output is correct |
20 |
Correct |
34 ms |
1920 KB |
Output is correct |
21 |
Correct |
22 ms |
2984 KB |
Output is correct |
22 |
Correct |
44 ms |
3192 KB |
Output is correct |
23 |
Correct |
14 ms |
3192 KB |
Output is correct |
24 |
Correct |
15 ms |
3072 KB |
Output is correct |
25 |
Correct |
27 ms |
2996 KB |
Output is correct |
26 |
Correct |
43 ms |
2800 KB |
Output is correct |
27 |
Correct |
12 ms |
3064 KB |
Output is correct |
28 |
Correct |
39 ms |
2792 KB |
Output is correct |
29 |
Correct |
42 ms |
3064 KB |
Output is correct |
30 |
Correct |
61 ms |
2928 KB |
Output is correct |
31 |
Correct |
53 ms |
2920 KB |
Output is correct |
32 |
Correct |
13 ms |
3056 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
21 ms |
2988 KB |
Output is correct |
35 |
Correct |
12 ms |
3064 KB |
Output is correct |
36 |
Correct |
44 ms |
2920 KB |
Output is correct |
37 |
Correct |
15 ms |
3192 KB |
Output is correct |
38 |
Correct |
9 ms |
3136 KB |
Output is correct |
39 |
Correct |
41 ms |
2920 KB |
Output is correct |
40 |
Correct |
50 ms |
3064 KB |
Output is correct |
41 |
Correct |
46 ms |
2928 KB |
Output is correct |
42 |
Correct |
60 ms |
2908 KB |
Output is correct |
43 |
Correct |
44 ms |
2976 KB |
Output is correct |
44 |
Correct |
38 ms |
2928 KB |
Output is correct |
45 |
Correct |
46 ms |
2792 KB |
Output is correct |
46 |
Correct |
40 ms |
2928 KB |
Output is correct |
47 |
Correct |
57 ms |
2932 KB |
Output is correct |
48 |
Correct |
42 ms |
2924 KB |
Output is correct |
49 |
Correct |
27 ms |
3052 KB |
Output is correct |
50 |
Correct |
43 ms |
2928 KB |
Output is correct |
51 |
Correct |
59 ms |
2920 KB |
Output is correct |
52 |
Correct |
55 ms |
2920 KB |
Output is correct |
53 |
Correct |
12 ms |
3072 KB |
Output is correct |
54 |
Correct |
33 ms |
3036 KB |
Output is correct |
55 |
Correct |
59 ms |
2928 KB |
Output is correct |
56 |
Correct |
26 ms |
3056 KB |
Output is correct |
57 |
Correct |
49 ms |
2928 KB |
Output is correct |
58 |
Correct |
52 ms |
2912 KB |
Output is correct |
59 |
Correct |
46 ms |
2920 KB |
Output is correct |
60 |
Correct |
40 ms |
2920 KB |
Output is correct |
61 |
Correct |
13 ms |
3060 KB |
Output is correct |
62 |
Correct |
11 ms |
3064 KB |
Output is correct |
63 |
Correct |
14 ms |
3072 KB |
Output is correct |
64 |
Correct |
12 ms |
3072 KB |
Output is correct |
65 |
Correct |
12 ms |
3064 KB |
Output is correct |
66 |
Correct |
5 ms |
1144 KB |
Output is correct |
67 |
Correct |
11 ms |
1152 KB |
Output is correct |
68 |
Correct |
16 ms |
3072 KB |
Output is correct |
69 |
Correct |
5 ms |
1152 KB |
Output is correct |
70 |
Correct |
16 ms |
3072 KB |
Output is correct |
71 |
Correct |
33 ms |
3016 KB |
Output is correct |
72 |
Correct |
14 ms |
3072 KB |
Output is correct |
73 |
Correct |
43 ms |
2920 KB |
Output is correct |
74 |
Correct |
65 ms |
2928 KB |
Output is correct |
75 |
Correct |
12 ms |
3072 KB |
Output is correct |
76 |
Correct |
50 ms |
3064 KB |
Output is correct |
77 |
Correct |
47 ms |
2928 KB |
Output is correct |
78 |
Correct |
17 ms |
3064 KB |
Output is correct |
79 |
Correct |
35 ms |
3072 KB |
Output is correct |
80 |
Correct |
51 ms |
2928 KB |
Output is correct |
81 |
Correct |
49 ms |
3088 KB |
Output is correct |
82 |
Correct |
62 ms |
2920 KB |
Output is correct |
83 |
Correct |
13 ms |
3072 KB |
Output is correct |
84 |
Correct |
30 ms |
3128 KB |
Output is correct |
85 |
Correct |
56 ms |
2920 KB |
Output is correct |
86 |
Correct |
21 ms |
2152 KB |
Output is correct |
87 |
Correct |
17 ms |
3064 KB |
Output is correct |
88 |
Correct |
53 ms |
3072 KB |
Output is correct |
89 |
Correct |
22 ms |
1904 KB |
Output is correct |
90 |
Correct |
13 ms |
3200 KB |
Output is correct |
91 |
Correct |
39 ms |
3072 KB |
Output is correct |
92 |
Correct |
49 ms |
3072 KB |
Output is correct |
93 |
Correct |
61 ms |
3072 KB |
Output is correct |
94 |
Correct |
44 ms |
3072 KB |
Output is correct |
95 |
Correct |
50 ms |
3072 KB |
Output is correct |
96 |
Correct |
41 ms |
3072 KB |
Output is correct |
97 |
Correct |
5 ms |
1280 KB |
Output is correct |