답안 #986104

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986104 2024-05-19T18:05:21 Z AlphaMale06 커다란 상품 (IOI17_prize) C++14
0 / 100
16 ms 22616 KB
#include <bits/stdc++.h>

#include "prize.h"

using namespace std;
using ll = long long;

//vector<int> ask(int i);

vector<int> a[200006];
int summ = 0;

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<200; i++){
        ll ind = rand();
        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:17:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   17 |     int s = l+r>>1;
      |             ~^~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 16 ms 22616 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 16 ms 22616 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -