#include <bits/stdc++.h>
#include <prize.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(a) a.size()
#define md(a, b) ((a) % b + b) % b
#define mod(a) md(a, MOD)
#define srt(a) sort(all(a))
#define mem(a, h) memset(a, (h), sizeof(a))
#define f first
#define s second
#define forn(i, n) for(int i = 0; i < n; i++)
#define fore(i, b, e) for(int i = b; i < e; i++)
#define forg(i, b, e, m) for(int i = b; i < e; i+=m)
//int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest order_of_key <
const int tam = 100010;
const int MOD = 1000000007;
const int MOD1 = 998244353;
const double EPS = 1e-9;
const double PI = acos(-1);
/*int er[] = {4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 3, 1, 4, 4, 4, 4, 2, 4, 4, 4, 3};
vector<int> ar(100034);
int q;
int n;
vector<int> ask(int i)
{
q++;
vector<int> res(2, 0);
fore(j, 0, i)
res[0] += ar[j] < ar[i];
fore(j, i + 1, 100034)
res[1] += ar[j] < ar[i];
return res;
}
int find_best(int n);
int main()
{
q = 0;
fore(i, 0, 100000) ar[i] = 4;
fore(i, 100000, 100034) ar[i] = er[i - 100000];
cout<<find_best(100034)<<'\n';
cout<<q<<'\n';
return 0;
}*/
int res, su;
void f(int b, int e, int mi, int ma)
{
int mini = (b + e) / 2, maxi = mini;
bool bo = true;
int can = 0;
while(true)
{
if(bo)
{
if(mini == b - 1) return;
auto ar = ask(mini);
if(ar[0] + ar[1] == su)
{
if(ar[0] > mi)
f(b, mini - 1, mi, ar[0]);
if(ma > ar[0] + can)
f(maxi + 1, e, ar[0] + can, ma);
return;
}
else
{
if(ar[0] + ar[1] == 0)
{
res = mini;
return;
}
can++;
bo = false;
maxi++;
}
}
else
{
if(maxi == e + 1) return;
auto ar = ask(maxi);
if(ar[0] + ar[1] == su)
{
if(ar[0] - can > mi)
f(b, mini - 1, mi, ar[0] - can);
if(ma > ar[0])
f(maxi + 1, e, ar[0], ma);
return;
}
else
{
if(ar[0] + ar[1] == 0)
{
res = maxi;
return;
}
can++;
bo = true;
mini++;
}
}
}
}
int find_best(int n)
{
pair<int, pair<int, int>> maxi{0,{0, 0}};
fore(i, 0, 473)
{
auto ar = ask(i);
if(ar[0] + ar[1] == 0)
return i;
if(ar[0] + ar[1] > 40)
{
maxi = mp(ar[0] + ar[1], mp(i, ar[0]));
break;
}
maxi = max(maxi, mp(ar[0] + ar[1], mp(i, ar[0])));
}
int posa, canso;
for(int i = n - 1; i > -1; i--)
{
auto ar = ask(i);
if(ar[0] + ar[1] == 0)
return i;
if(ar[0] + ar[1] == maxi.f)
{
canso = ar[0];
posa = i;
break;
}
}
su = maxi.f;
f(maxi.s.f + 1, posa - 1, maxi.s.s, maxi.f);
return res;
}
// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:136:13: warning: variable 'canso' set but not used [-Wunused-but-set-variable]
136 | int posa, canso;
| ^~~~~
prize.cpp:136:7: warning: 'posa' may be used uninitialized in this function [-Wmaybe-uninitialized]
136 | int posa, canso;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
6 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
368 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
6 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
6 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
364 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
7 ms |
256 KB |
Output is correct |
5 |
Correct |
7 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
7 ms |
256 KB |
Output is correct |
9 |
Correct |
7 ms |
256 KB |
Output is correct |
10 |
Correct |
8 ms |
256 KB |
Output is correct |
11 |
Correct |
9 ms |
256 KB |
Output is correct |
12 |
Correct |
9 ms |
256 KB |
Output is correct |
13 |
Correct |
13 ms |
256 KB |
Output is correct |
14 |
Correct |
11 ms |
256 KB |
Output is correct |
15 |
Correct |
47 ms |
256 KB |
Output is correct |
16 |
Correct |
40 ms |
256 KB |
Output is correct |
17 |
Correct |
60 ms |
256 KB |
Output is correct |
18 |
Correct |
54 ms |
256 KB |
Output is correct |
19 |
Correct |
37 ms |
256 KB |
Output is correct |
20 |
Correct |
27 ms |
256 KB |
Output is correct |
21 |
Correct |
25 ms |
256 KB |
Output is correct |
22 |
Correct |
35 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
256 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
35 ms |
256 KB |
Output is correct |
26 |
Correct |
40 ms |
256 KB |
Output is correct |
27 |
Correct |
6 ms |
256 KB |
Output is correct |
28 |
Correct |
37 ms |
256 KB |
Output is correct |
29 |
Correct |
40 ms |
256 KB |
Output is correct |
30 |
Correct |
44 ms |
256 KB |
Output is correct |
31 |
Correct |
52 ms |
256 KB |
Output is correct |
32 |
Correct |
9 ms |
256 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
42 ms |
256 KB |
Output is correct |
35 |
Correct |
7 ms |
256 KB |
Output is correct |
36 |
Correct |
40 ms |
256 KB |
Output is correct |
37 |
Correct |
11 ms |
256 KB |
Output is correct |
38 |
Correct |
7 ms |
256 KB |
Output is correct |
39 |
Correct |
36 ms |
256 KB |
Output is correct |
40 |
Correct |
42 ms |
256 KB |
Output is correct |
41 |
Correct |
23 ms |
256 KB |
Output is correct |
42 |
Correct |
47 ms |
256 KB |
Output is correct |
43 |
Correct |
35 ms |
256 KB |
Output is correct |
44 |
Correct |
42 ms |
256 KB |
Output is correct |
45 |
Correct |
20 ms |
376 KB |
Output is correct |
46 |
Correct |
43 ms |
256 KB |
Output is correct |
47 |
Correct |
53 ms |
256 KB |
Output is correct |
48 |
Correct |
35 ms |
256 KB |
Output is correct |
49 |
Correct |
56 ms |
256 KB |
Output is correct |
50 |
Correct |
52 ms |
360 KB |
Output is correct |
51 |
Correct |
35 ms |
256 KB |
Output is correct |
52 |
Correct |
24 ms |
376 KB |
Output is correct |
53 |
Correct |
8 ms |
256 KB |
Output is correct |
54 |
Correct |
41 ms |
368 KB |
Output is correct |
55 |
Correct |
51 ms |
256 KB |
Output is correct |
56 |
Correct |
51 ms |
256 KB |
Output is correct |
57 |
Correct |
56 ms |
256 KB |
Output is correct |
58 |
Correct |
23 ms |
372 KB |
Output is correct |
59 |
Correct |
47 ms |
256 KB |
Output is correct |
60 |
Correct |
38 ms |
256 KB |
Output is correct |
61 |
Correct |
6 ms |
256 KB |
Output is correct |
62 |
Correct |
5 ms |
256 KB |
Output is correct |
63 |
Correct |
6 ms |
256 KB |
Output is correct |
64 |
Correct |
7 ms |
256 KB |
Output is correct |
65 |
Correct |
3 ms |
384 KB |
Output is correct |
66 |
Correct |
1 ms |
376 KB |
Output is correct |
67 |
Correct |
3 ms |
376 KB |
Output is correct |
68 |
Correct |
6 ms |
256 KB |
Output is correct |
69 |
Correct |
1 ms |
256 KB |
Output is correct |
70 |
Correct |
4 ms |
256 KB |
Output is correct |
71 |
Correct |
28 ms |
256 KB |
Output is correct |
72 |
Correct |
11 ms |
256 KB |
Output is correct |
73 |
Correct |
44 ms |
256 KB |
Output is correct |
74 |
Correct |
46 ms |
256 KB |
Output is correct |
75 |
Correct |
6 ms |
256 KB |
Output is correct |
76 |
Correct |
38 ms |
256 KB |
Output is correct |
77 |
Correct |
38 ms |
256 KB |
Output is correct |
78 |
Correct |
11 ms |
256 KB |
Output is correct |
79 |
Correct |
17 ms |
256 KB |
Output is correct |
80 |
Correct |
44 ms |
256 KB |
Output is correct |
81 |
Correct |
50 ms |
256 KB |
Output is correct |
82 |
Correct |
36 ms |
256 KB |
Output is correct |
83 |
Correct |
6 ms |
256 KB |
Output is correct |
84 |
Correct |
45 ms |
256 KB |
Output is correct |
85 |
Correct |
42 ms |
256 KB |
Output is correct |
86 |
Correct |
5 ms |
256 KB |
Output is correct |
87 |
Correct |
4 ms |
384 KB |
Output is correct |
88 |
Correct |
6 ms |
256 KB |
Output is correct |
89 |
Correct |
7 ms |
256 KB |
Output is correct |
90 |
Correct |
5 ms |
256 KB |
Output is correct |
91 |
Correct |
4 ms |
256 KB |
Output is correct |
92 |
Correct |
6 ms |
256 KB |
Output is correct |
93 |
Correct |
9 ms |
256 KB |
Output is correct |
94 |
Correct |
10 ms |
256 KB |
Output is correct |
95 |
Correct |
9 ms |
256 KB |
Output is correct |
96 |
Correct |
8 ms |
256 KB |
Output is correct |
97 |
Correct |
6 ms |
256 KB |
Output is correct |