Submission #52718

# Submission time Handle Problem Language Result Execution time Memory
52718 2018-06-26T12:34:51 Z KieranHorgan The Big Prize (IOI17_prize) C++17
100 / 100
187 ms 31668 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> res[200000];
set<int> nextPos, curPos;
vector<int> positions;
int smaller, nextSmaller;
int flag=-1;

void get(int i) {
  if(res[i][0] != -1 && res[i][1] != -1) return;
  res[i] = ask(i);
  if(res[i][0]+res[i][1]==0) flag=i;
}

void dac(int lo, int hi) {
  // cerr << lo << " " << hi << endl;
  if(lo == hi) return;
  get(positions[lo]);
  if(flag!=-1) {return;}
  get(positions[hi]);
  if(flag!=-1) {return;}
  if(res[positions[lo]][0]==res[positions[hi]][0] &&
     res[positions[lo]][1]==res[positions[hi]][1]) return;
  if(res[positions[lo]][1]-res[positions[hi]][1]==hi-lo-1) {
    for(int i = lo+1; i <= hi-1; i++) {
      nextPos.insert(positions[i]);
      get(positions[i]);
      if(flag!=-1) {return;}
      nextSmaller = max(nextSmaller, res[positions[i]][0]+res[positions[i]][1]);
    }
    return;
  }
  int mid = (hi+lo)/2;
  get(positions[mid]);
  if(flag!=-1) {return;}
  if(res[positions[mid]][0]+res[positions[mid]][1] == smaller) {
    dac(lo, mid);
    dac(mid, hi);
    return;
  }

  int m1 = mid;
  while(m1 != lo && res[positions[m1]][0]+res[positions[m1]][1] != smaller) {
    nextPos.insert(m1);
    nextSmaller = max(nextSmaller, res[positions[m1]][0]+res[positions[m1]][1]);
    m1--;
    get(positions[m1]);
  if(flag!=-1) {return;}}

  dac(lo, m1);

  int m2 = mid;
  while(m2 != hi && res[positions[m2]][0]+res[positions[m2]][1] != smaller) {
    nextPos.insert(m2);
    nextSmaller = max(nextSmaller, res[positions[m2]][0]+res[positions[m2]][1]);
    m2++;
    get(positions[m2]);
  if(flag!=-1) {return;}}

  dac(m2, hi);

  return;
}

int find_best(int n) {
  int x = 1;
  int soFar = 1;
  int i;
  for(i = 1; x <= 200000; i++) {
  	// cerr << i << ": " << x << " " << soFar << endl;
    x = x*x+1;
    soFar += x;
  }
  // cerr << i << ": " << x << " " << soFar << endl;

  for(int i = 0; i < n; i++) {
    res[i] = {-1, -1};
  }

  for(int i = 0; i < 472 && i < n; i++) {
    get(i);
    if(flag!=-1) return flag;
    if(res[i][0]+res[i][1]==0) return i;
    smaller = max(smaller, res[i][0]+res[i][1]);
    if(res[i][0]+res[i][1]>34) break;
  }

  for(int i = 0; i < n; i++) nextPos.insert(i);
  nextSmaller = smaller;
  
  while(nextPos.size() > 500) {
    curPos = nextPos;
    positions = {};
    for(auto x: curPos) {
      if(res[x][0]+res[x][1]==0) return x;
      positions.push_back(x);
    }
    nextPos.clear();
    smaller = nextSmaller;
    nextSmaller = 0;

    int lo = 0;
    get(lo);
    if(flag!=-1) return flag;
    while(res[positions[lo]][0]+res[positions[lo]][1] < smaller) {
      nextPos.insert(positions[lo]);
      lo++;
      get(lo);
    if(flag!=-1) return flag;}

    int hi = positions.size()-1;
    get(hi);
    if(flag!=-1) return flag;
    while(res[positions[hi]][0]+res[positions[hi]][1] < smaller) {
      nextPos.insert(positions[hi]);
      hi--;
      get(hi);
    if(flag!=-1) return flag;}

    dac(lo, hi);
    if(flag!=-1) return flag;
  }

  for(auto x: nextPos) {
    get(x);
    if(res[x][0]+res[x][1]==0) return x;
  }

  return *(nextPos.begin());
}
# Verdict Execution time Memory Grader output
1 Correct 122 ms 31172 KB Output is correct
2 Correct 118 ms 31288 KB Output is correct
3 Correct 116 ms 31288 KB Output is correct
4 Correct 141 ms 31288 KB Output is correct
5 Correct 121 ms 31352 KB Output is correct
6 Correct 22 ms 31352 KB Output is correct
7 Correct 130 ms 31440 KB Output is correct
8 Correct 121 ms 31440 KB Output is correct
9 Correct 126 ms 31440 KB Output is correct
10 Correct 132 ms 31440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 31440 KB Output is correct
2 Correct 116 ms 31440 KB Output is correct
3 Correct 118 ms 31520 KB Output is correct
4 Correct 120 ms 31520 KB Output is correct
5 Correct 123 ms 31520 KB Output is correct
6 Correct 21 ms 31520 KB Output is correct
7 Correct 124 ms 31668 KB Output is correct
8 Correct 126 ms 31668 KB Output is correct
9 Correct 137 ms 31668 KB Output is correct
10 Correct 118 ms 31668 KB Output is correct
11 Correct 124 ms 31668 KB Output is correct
12 Correct 125 ms 31668 KB Output is correct
13 Correct 124 ms 31668 KB Output is correct
14 Correct 22 ms 31668 KB Output is correct
15 Correct 122 ms 31668 KB Output is correct
16 Correct 157 ms 31668 KB Output is correct
17 Correct 132 ms 31668 KB Output is correct
18 Correct 159 ms 31668 KB Output is correct
19 Correct 120 ms 31668 KB Output is correct
20 Correct 68 ms 31668 KB Output is correct
21 Correct 136 ms 31668 KB Output is correct
22 Correct 142 ms 31668 KB Output is correct
23 Correct 120 ms 31668 KB Output is correct
24 Correct 122 ms 31668 KB Output is correct
25 Correct 130 ms 31668 KB Output is correct
26 Correct 134 ms 31668 KB Output is correct
27 Correct 118 ms 31668 KB Output is correct
28 Correct 148 ms 31668 KB Output is correct
29 Correct 158 ms 31668 KB Output is correct
30 Correct 187 ms 31668 KB Output is correct
31 Correct 113 ms 31668 KB Output is correct
32 Correct 120 ms 31668 KB Output is correct
33 Correct 6 ms 31668 KB Output is correct
34 Correct 126 ms 31668 KB Output is correct
35 Correct 120 ms 31668 KB Output is correct
36 Correct 123 ms 31668 KB Output is correct
37 Correct 122 ms 31668 KB Output is correct
38 Correct 123 ms 31668 KB Output is correct
39 Correct 134 ms 31668 KB Output is correct
40 Correct 146 ms 31668 KB Output is correct
41 Correct 146 ms 31668 KB Output is correct
42 Correct 133 ms 31668 KB Output is correct
43 Correct 149 ms 31668 KB Output is correct
44 Correct 130 ms 31668 KB Output is correct
45 Correct 136 ms 31668 KB Output is correct
46 Correct 117 ms 31668 KB Output is correct
47 Correct 143 ms 31668 KB Output is correct
48 Correct 139 ms 31668 KB Output is correct
49 Correct 118 ms 31668 KB Output is correct
50 Correct 147 ms 31668 KB Output is correct
51 Correct 134 ms 31668 KB Output is correct
52 Correct 118 ms 31668 KB Output is correct
53 Correct 127 ms 31668 KB Output is correct
54 Correct 134 ms 31668 KB Output is correct
55 Correct 129 ms 31668 KB Output is correct
56 Correct 140 ms 31668 KB Output is correct
57 Correct 132 ms 31668 KB Output is correct
58 Correct 145 ms 31668 KB Output is correct
59 Correct 152 ms 31668 KB Output is correct
60 Correct 140 ms 31668 KB Output is correct
61 Correct 123 ms 31668 KB Output is correct
62 Correct 122 ms 31668 KB Output is correct
63 Correct 132 ms 31668 KB Output is correct
64 Correct 116 ms 31668 KB Output is correct
65 Correct 121 ms 31668 KB Output is correct
66 Correct 114 ms 31668 KB Output is correct
67 Correct 117 ms 31668 KB Output is correct
68 Correct 24 ms 31668 KB Output is correct
69 Correct 123 ms 31668 KB Output is correct
70 Correct 126 ms 31668 KB Output is correct
71 Correct 140 ms 31668 KB Output is correct
72 Correct 115 ms 31668 KB Output is correct
73 Correct 162 ms 31668 KB Output is correct
74 Correct 181 ms 31668 KB Output is correct
75 Correct 134 ms 31668 KB Output is correct
76 Correct 176 ms 31668 KB Output is correct
77 Correct 171 ms 31668 KB Output is correct
78 Correct 117 ms 31668 KB Output is correct
79 Correct 137 ms 31668 KB Output is correct
80 Correct 156 ms 31668 KB Output is correct
81 Correct 136 ms 31668 KB Output is correct
82 Correct 174 ms 31668 KB Output is correct
83 Correct 139 ms 31668 KB Output is correct
84 Correct 165 ms 31668 KB Output is correct
85 Correct 155 ms 31668 KB Output is correct
86 Correct 128 ms 31668 KB Output is correct
87 Correct 123 ms 31668 KB Output is correct
88 Correct 120 ms 31668 KB Output is correct
89 Correct 125 ms 31668 KB Output is correct
90 Correct 118 ms 31668 KB Output is correct
91 Correct 128 ms 31668 KB Output is correct
92 Correct 114 ms 31668 KB Output is correct
93 Correct 126 ms 31668 KB Output is correct
94 Correct 119 ms 31668 KB Output is correct
95 Correct 124 ms 31668 KB Output is correct
96 Correct 128 ms 31668 KB Output is correct
97 Correct 136 ms 31668 KB Output is correct