Submission #986097

# Submission time Handle Problem Language Result Execution time Memory
986097 2024-05-19T17:56:15 Z AlphaMale06 The Big Prize (IOI17_prize) C++17
0 / 100
19 ms 22656 KB
#include <bits/stdc++.h>

#include "prize.h"

using namespace std;
using ll = long long;

//vector<int> ask(int i);
const int N = 2e5+3;

vector<int> a[N];
int summ;

int solve(int l, int r){
    if(l+1>=r)return 0;
    int cnt = a[l][1]-a[r][1];
    if(cnt==0)return 0;
    int s = l+r>>1;
    if(a[s][0]==-1)a[s]=ask(s);
    if(a[s][0]+a[s][1]==summ)return max(solve(l, s), solve(s, r));
    if(a[s][0]+a[s][1]==0)return s;
    int R = s-1, L = s+1;
    for(int i=s-1; i>=l; i--){
        if(a[i][0]==-1)a[i]=ask(i);
        if(a[i][0]+a[i][1]==0)return i;
        if(a[i][0]+a[i][1]==summ){
            R=i;
            break;
        }
    }
    for(int i=s+1; i<=r; i++){
        if(a[i][0]==-1)a[i]=ask(i);
        if(a[i][0]+a[i][1]==0)return i;
        if(a[i][0]+a[i][1]==summ){
            L=i;
            break;
        }
    }
    return max(solve(l, R), solve(L, r));
}

int find_best(int n){
	if(n<=5000){
        for(int i=0; i<n; i++){
            vector<int> ans = ask(i);
            if(ans[0]==0 && ans[1]==0)return i;
        }
	}
	for(int i=0; i< n; i++){
        a[i].push_back(-1);
	}
    for(int i=0; i<20; i++){
        ll ind = rand() * 12ll * rand() + 1000000009ll*rand();
        ind%=n;
        if(a[ind][0]!=-1){
            i--;
            continue;
        }
        vector<int> ans = ask(ind);
        a[ind]=ans;
        summ=max(summ, ans[0]+ans[1]);
        if(ans[0]+ans[1]==0)return ind;
    }
    int L = 0, R = n-1;
    for(int i=0; i<n; i++){
        if(a[i][0]==-1)a[i] = ask(i);
        if(a[i][0]+a[i][1]==summ){
            L=i;
            break;
        }
        if(a[i][0]+a[i][1]==0)return i;
    }
    for(int i=n-1; i>=0; i--){
        if(a[i][0]==-1)a[i]=ask(i);
        if(a[i][0]+a[i][1]==summ){
            R=i;
            break;
        }
        if(a[i][0]+a[i][1]==0)return i;
    }
    return solve(L, R);
}

Compilation message

prize.cpp: In function 'int solve(int, int)':
prize.cpp:18:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |     int s = l+r>>1;
      |             ~^~
# Verdict Execution time Memory Grader output
1 Runtime error 19 ms 22656 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 22640 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -