답안 #945112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945112 2024-03-13T12:16:28 Z Wansur 커다란 상품 (IOI17_prize) C++14
0 / 100
63 ms 5804 KB
#include <bits/stdc++.h>
#define f first
#define s second
#define ent '\n'

typedef long long ll;
using namespace std;

struct asd{
    int a, b, w, ca, cb;
};

vector<int> ask(int i);
const string out[2]={"NO\n","YES\n"};
const ll dx[]={0,1,0,-1,-1,1,1,-1};
const ll dy[]={1,0,-1,0,-1,1,-1,1};
const int mod=998244353;
const int md=1e9+7;
const int mx=2e5+12;
const bool T=0;

vector<int> ans[mx];
int ma;

vector<int> Ask(int i){
    if(ans[i].size()>0){
        return ans[i];
    }
    ans[i]=ask(i);
    return ans[i];
}

int find(int l,int r,int x,int left,int right){
    if(!x || l>r)return -1;
    int mid=l+r>>1, cnt=0;
    for(int i=mid;i<=r;i++){
        auto a=ask(i);
        if(a[0]+a[1]<ma){
            if(a[0]+a[1]==0){
                return i;
            }
            cnt++;
        }
        else{
            int val=find(i+1, r, a[1] - right, a[0], right);
            if(val!=-1){
                return val;
            }
            return find(l, mid-1, a[0] - left - cnt, left, a[1] + cnt);
        }
    }
    return find(l, mid-1, x-cnt, left, right - cnt);
}

int find_best(int n){
    srand(time(0));
    int pos=0, c=0;
    for(int i=0;i<478;i++){
        auto a=Ask(n-i-1);
        if(a[0]+a[1]==0){
            return n-i-1;
        }
        if(a[0]+a[1]>ma){
            ma=a[0]+a[1];
            pos=i;
        }
        if(ma>sqrt(n))break;
    }
    for(int i=0;i<=pos;i++){
        auto a=Ask(n-i-1);
        pos=n-i-1;
        if(a[0]+a[1]!=ma){
            c++;
        }
    }
    return find(0, pos-1, ma - c, 0, c);
}

Compilation message

prize.cpp: In function 'int find(int, int, int, int, int)':
prize.cpp:35:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |     int mid=l+r>>1, cnt=0;
      |             ~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 50 ms 5624 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 5804 KB Incorrect
2 Halted 0 ms 0 KB -