Submission #52425

# Submission time Handle Problem Language Result Execution time Memory
52425 2018-06-25T23:12:28 Z KieranHorgan The Big Prize (IOI17_prize) C++17
0 / 100
22 ms 11448 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 Incorrect 20 ms 11256 KB Token "1:" doesn't correspond to pattern "[A-B]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 11448 KB Token "1:" doesn't correspond to pattern "[A-B]{1}"
2 Halted 0 ms 0 KB -