Submission #964731

# Submission time Handle Problem Language Result Execution time Memory
964731 2024-04-17T12:18:18 Z AdamGS The Big Prize (IOI17_prize) C++17
100 / 100
32 ms 7388 KB
#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7;
vector<int>P[LIM];
int odw[LIM], ma, n;
void pytaj(int x) {
  if(odw[x]) return;
  odw[x]=1;
  P[x]=ask(x);
  ma=max(ma, P[x][0]+P[x][1]);
}
bool dobry(int x) {
  if(x<0 || x>=n) return false;
  pytaj(x);
  return P[x][0]+P[x][1]<ma;
}
bool wygrany(int x) {
  if(x<0 || x>=n) return false;
  pytaj(x);
  return P[x][0]+P[x][1]==0;
}
int solve(int l, int r) {
  if(l>r) return -1;
  if(wygrany(l-1)) return l-1;
  if(dobry(l-1)) return solve(l+1, r);
  if(wygrany(r+1)) return r+1;
  if(dobry(r+1)) return solve(l, r-1);
  int a=ma;
  if(l) a=P[l-1][1];
  if(r<n-1) a-=P[r+1][1];
  if(!a) return -1;
  int mid=(l+r)/2;
  if(wygrany(mid)) return mid;
  int p=solve(l, mid-1);
  if(p!=-1) return p;
  return solve(mid+1, r);
}
int find_best(int N) {
  n=N;
  if(n<=5000) {
    rep(i, n) {
      pytaj(i);
      if(P[i][0]+P[i][1]==0) return i;
    }
  }
  int x=n/500;
  rep(i, 499) if(wygrany(x*(i+1))) return x*(i+1);
  int p=solve(0, x-1);
  if(p!=-1) return p;
  rep(i, 498) {
    p=solve(x*(i+1)+1, x*(i+2)-1);
    if(p!=-1) return p;
  }
  return solve(x*499+1, n-1);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5924 KB Output is correct
2 Correct 4 ms 6312 KB Output is correct
3 Correct 4 ms 6044 KB Output is correct
4 Correct 8 ms 6312 KB Output is correct
5 Correct 3 ms 5792 KB Output is correct
6 Correct 5 ms 6184 KB Output is correct
7 Correct 3 ms 6048 KB Output is correct
8 Correct 4 ms 6048 KB Output is correct
9 Correct 4 ms 6300 KB Output is correct
10 Correct 4 ms 5924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 6420 KB Output is correct
2 Correct 3 ms 5924 KB Output is correct
3 Correct 5 ms 6296 KB Output is correct
4 Correct 4 ms 6176 KB Output is correct
5 Correct 3 ms 5788 KB Output is correct
6 Correct 4 ms 6180 KB Output is correct
7 Correct 3 ms 6236 KB Output is correct
8 Correct 3 ms 5920 KB Output is correct
9 Correct 6 ms 6300 KB Output is correct
10 Correct 3 ms 5924 KB Output is correct
11 Correct 6 ms 6148 KB Output is correct
12 Correct 4 ms 6168 KB Output is correct
13 Correct 6 ms 6400 KB Output is correct
14 Correct 6 ms 5992 KB Output is correct
15 Correct 6 ms 6056 KB Output is correct
16 Correct 20 ms 6500 KB Output is correct
17 Correct 5 ms 5928 KB Output is correct
18 Correct 32 ms 6760 KB Output is correct
19 Correct 6 ms 6076 KB Output is correct
20 Correct 7 ms 6104 KB Output is correct
21 Correct 10 ms 6180 KB Output is correct
22 Correct 4 ms 6308 KB Output is correct
23 Correct 4 ms 6328 KB Output is correct
24 Correct 3 ms 6052 KB Output is correct
25 Correct 13 ms 6260 KB Output is correct
26 Correct 13 ms 6420 KB Output is correct
27 Correct 5 ms 6180 KB Output is correct
28 Correct 28 ms 6564 KB Output is correct
29 Correct 17 ms 6224 KB Output is correct
30 Correct 24 ms 6276 KB Output is correct
31 Correct 5 ms 6568 KB Output is correct
32 Correct 6 ms 6860 KB Output is correct
33 Correct 1 ms 5720 KB Output is correct
34 Correct 10 ms 6452 KB Output is correct
35 Correct 4 ms 6388 KB Output is correct
36 Correct 7 ms 6312 KB Output is correct
37 Correct 4 ms 6564 KB Output is correct
38 Correct 4 ms 6180 KB Output is correct
39 Correct 12 ms 6192 KB Output is correct
40 Correct 22 ms 6828 KB Output is correct
41 Correct 14 ms 6176 KB Output is correct
42 Correct 11 ms 6488 KB Output is correct
43 Correct 18 ms 6220 KB Output is correct
44 Correct 10 ms 6588 KB Output is correct
45 Correct 8 ms 6448 KB Output is correct
46 Correct 4 ms 6636 KB Output is correct
47 Correct 11 ms 6816 KB Output is correct
48 Correct 21 ms 6460 KB Output is correct
49 Correct 5 ms 6180 KB Output is correct
50 Correct 23 ms 7020 KB Output is correct
51 Correct 12 ms 6572 KB Output is correct
52 Correct 4 ms 6048 KB Output is correct
53 Correct 4 ms 5920 KB Output is correct
54 Correct 14 ms 6464 KB Output is correct
55 Correct 4 ms 6052 KB Output is correct
56 Correct 21 ms 6456 KB Output is correct
57 Correct 19 ms 6480 KB Output is correct
58 Correct 17 ms 6824 KB Output is correct
59 Correct 16 ms 6476 KB Output is correct
60 Correct 12 ms 6240 KB Output is correct
61 Correct 4 ms 6052 KB Output is correct
62 Correct 4 ms 6308 KB Output is correct
63 Correct 4 ms 6048 KB Output is correct
64 Correct 4 ms 5924 KB Output is correct
65 Correct 5 ms 6300 KB Output is correct
66 Correct 5 ms 6564 KB Output is correct
67 Correct 4 ms 6044 KB Output is correct
68 Correct 5 ms 6176 KB Output is correct
69 Correct 7 ms 6436 KB Output is correct
70 Correct 4 ms 6056 KB Output is correct
71 Correct 23 ms 6548 KB Output is correct
72 Correct 7 ms 6424 KB Output is correct
73 Correct 31 ms 6808 KB Output is correct
74 Correct 23 ms 6484 KB Output is correct
75 Correct 4 ms 6336 KB Output is correct
76 Correct 24 ms 6724 KB Output is correct
77 Correct 28 ms 7388 KB Output is correct
78 Correct 5 ms 6252 KB Output is correct
79 Correct 15 ms 6196 KB Output is correct
80 Correct 28 ms 6256 KB Output is correct
81 Correct 26 ms 6604 KB Output is correct
82 Correct 24 ms 6516 KB Output is correct
83 Correct 4 ms 6512 KB Output is correct
84 Correct 23 ms 6484 KB Output is correct
85 Correct 26 ms 6504 KB Output is correct
86 Correct 7 ms 6428 KB Output is correct
87 Correct 4 ms 6252 KB Output is correct
88 Correct 10 ms 6448 KB Output is correct
89 Correct 9 ms 6252 KB Output is correct
90 Correct 4 ms 6256 KB Output is correct
91 Correct 7 ms 6756 KB Output is correct
92 Correct 7 ms 6512 KB Output is correct
93 Correct 10 ms 6260 KB Output is correct
94 Correct 10 ms 6640 KB Output is correct
95 Correct 8 ms 6516 KB Output is correct
96 Correct 10 ms 6452 KB Output is correct
97 Correct 10 ms 6456 KB Output is correct