Submission #571262

# Submission time Handle Problem Language Result Execution time Memory
571262 2022-06-01T15:29:12 Z ian86 The Big Prize (IOI17_prize) C++14
100 / 100
54 ms 2184 KB
#include <vector>
#include <cmath>
#include <cstring>
#include "prize.h"
#define X first
#define Y second
using namespace std;

typedef pair<int,int> pii;

int numb;
pii P[210000];
bool mark[210000];
vector<int>vtmp;

pii query(int x)
{
  if(mark[x]) return P[x];
  mark[x]=true;
  vtmp=ask(x);
  pii tmp=pii(vtmp[0],vtmp[1]);
  if(tmp.X+tmp.Y==0) throw x;
  return P[x]=tmp;
}

void bs(int l,int r,int nl,int nr)
{
  if(l>r) return;
  for(int i=0;i<=r-l;i++)
    {
      int mid,midl=(l+r)/2-i/2,midr=(l+r)/2+(i+1)/2;
      if(i%2==0) mid=midl;
      else mid=midr;
      pii tmp=query(mid);
      if(tmp.X+tmp.Y==numb)
	{
	  int tmpl=(i%2==0?0:midr-midl);
	  int tmpr=(i%2==1?0:midr-midl);
	  if(tmp.X-tmpl>nl) bs(l,midl-1,nl,tmp.Y+tmpl);
	  if(tmp.Y-tmpr>nr) bs(midr+1,r,tmp.X+tmpr,nr);
	  break;
	}
    }
}

int find_best(int n)
{
  if(n==1) return 0;
  try{
    numb=0;
    memset(mark,false,sizeof mark);
    int p=0;
    for(int i=0;i<sqrt(n)+30 && i<n && numb<=26;i++)
      {
	pii tmp=query(i);
	if(tmp.X+tmp.Y>numb) p=i;
	numb=max(numb,tmp.X+tmp.Y);
      }
    bs(p,n-1,p,0);
  }
  catch(int ans){
    return ans;
  }
  return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 556 KB Output is correct
2 Correct 9 ms 548 KB Output is correct
3 Correct 6 ms 592 KB Output is correct
4 Correct 9 ms 496 KB Output is correct
5 Correct 9 ms 500 KB Output is correct
6 Correct 3 ms 552 KB Output is correct
7 Correct 7 ms 552 KB Output is correct
8 Correct 6 ms 552 KB Output is correct
9 Correct 10 ms 464 KB Output is correct
10 Correct 7 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 556 KB Output is correct
2 Correct 8 ms 496 KB Output is correct
3 Correct 8 ms 556 KB Output is correct
4 Correct 7 ms 548 KB Output is correct
5 Correct 8 ms 508 KB Output is correct
6 Correct 2 ms 456 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 7 ms 548 KB Output is correct
9 Correct 9 ms 500 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 6 ms 712 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 7 ms 1096 KB Output is correct
14 Correct 4 ms 592 KB Output is correct
15 Correct 8 ms 812 KB Output is correct
16 Correct 21 ms 1844 KB Output is correct
17 Correct 2 ms 508 KB Output is correct
18 Correct 32 ms 2076 KB Output is correct
19 Correct 3 ms 552 KB Output is correct
20 Correct 11 ms 784 KB Output is correct
21 Correct 23 ms 1064 KB Output is correct
22 Correct 4 ms 628 KB Output is correct
23 Correct 7 ms 592 KB Output is correct
24 Correct 3 ms 556 KB Output is correct
25 Correct 24 ms 1304 KB Output is correct
26 Correct 22 ms 1440 KB Output is correct
27 Correct 7 ms 628 KB Output is correct
28 Correct 20 ms 1920 KB Output is correct
29 Correct 17 ms 1740 KB Output is correct
30 Correct 32 ms 2096 KB Output is correct
31 Correct 2 ms 552 KB Output is correct
32 Correct 8 ms 968 KB Output is correct
33 Correct 2 ms 464 KB Output is correct
34 Correct 18 ms 1016 KB Output is correct
35 Correct 9 ms 676 KB Output is correct
36 Correct 12 ms 804 KB Output is correct
37 Correct 4 ms 676 KB Output is correct
38 Correct 8 ms 584 KB Output is correct
39 Correct 23 ms 1248 KB Output is correct
40 Correct 44 ms 2056 KB Output is correct
41 Correct 29 ms 1352 KB Output is correct
42 Correct 30 ms 1504 KB Output is correct
43 Correct 20 ms 1320 KB Output is correct
44 Correct 10 ms 1184 KB Output is correct
45 Correct 15 ms 936 KB Output is correct
46 Correct 2 ms 540 KB Output is correct
47 Correct 19 ms 1060 KB Output is correct
48 Correct 30 ms 1716 KB Output is correct
49 Correct 6 ms 584 KB Output is correct
50 Correct 43 ms 2024 KB Output is correct
51 Correct 10 ms 1140 KB Output is correct
52 Correct 3 ms 564 KB Output is correct
53 Correct 6 ms 708 KB Output is correct
54 Correct 26 ms 1192 KB Output is correct
55 Correct 2 ms 540 KB Output is correct
56 Correct 54 ms 2020 KB Output is correct
57 Correct 26 ms 1628 KB Output is correct
58 Correct 29 ms 1812 KB Output is correct
59 Correct 27 ms 1436 KB Output is correct
60 Correct 27 ms 1320 KB Output is correct
61 Correct 7 ms 712 KB Output is correct
62 Correct 7 ms 584 KB Output is correct
63 Correct 8 ms 760 KB Output is correct
64 Correct 9 ms 680 KB Output is correct
65 Correct 2 ms 540 KB Output is correct
66 Correct 9 ms 548 KB Output is correct
67 Correct 4 ms 544 KB Output is correct
68 Correct 6 ms 548 KB Output is correct
69 Correct 6 ms 548 KB Output is correct
70 Correct 3 ms 544 KB Output is correct
71 Correct 49 ms 2120 KB Output is correct
72 Correct 7 ms 1104 KB Output is correct
73 Correct 54 ms 2088 KB Output is correct
74 Correct 53 ms 2100 KB Output is correct
75 Correct 9 ms 720 KB Output is correct
76 Correct 38 ms 2036 KB Output is correct
77 Correct 42 ms 2088 KB Output is correct
78 Correct 7 ms 1168 KB Output is correct
79 Correct 27 ms 2024 KB Output is correct
80 Correct 50 ms 2092 KB Output is correct
81 Correct 45 ms 2040 KB Output is correct
82 Correct 45 ms 2184 KB Output is correct
83 Correct 9 ms 720 KB Output is correct
84 Correct 38 ms 2084 KB Output is correct
85 Correct 41 ms 2112 KB Output is correct
86 Correct 4 ms 520 KB Output is correct
87 Correct 5 ms 584 KB Output is correct
88 Correct 8 ms 556 KB Output is correct
89 Correct 7 ms 512 KB Output is correct
90 Correct 8 ms 592 KB Output is correct
91 Correct 5 ms 592 KB Output is correct
92 Correct 7 ms 584 KB Output is correct
93 Correct 11 ms 840 KB Output is correct
94 Correct 10 ms 1004 KB Output is correct
95 Correct 8 ms 976 KB Output is correct
96 Correct 10 ms 848 KB Output is correct
97 Correct 8 ms 816 KB Output is correct