답안 #430408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430408 2021-06-16T13:26:02 Z Dremix10 커다란 상품 (IOI17_prize) C++17
90 / 100
139 ms 7776 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
#define endl '\n'
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
const int N = 3e5+1;
const ll INF = 2e18;
const int MOD = 1e9+7;

vector<int> ask(int i);

vector<vector<int> > memo(N);

const int block = 5;
int nn;

vector<int> askme(int i){
    if(memo[i].empty()){
        memo[i] = ask(i);
    }
    return memo[i];
}

int seen,cheap;

int go(int b){
    for(int i=b*block;i<min(nn,(b+1)*block);i++){
        vector<int> arr = askme(i);
        if(arr[0] + arr[1] == 0)
            return i;
        if(arr[0] + arr[1] < cheap)
            seen++;
    }
    return -1;
}

int find_best(int n) {
    /// the second to smallest price is in at most 450 boxes
    /// the maximum amount of prizes is 5

    nn = n;
    int blocks = (n+4)/5;

    for(int i=0;i<min(500,n);i++){
        vector<int> arr = askme(i);
        cheap = max(cheap,arr[0] + arr[1]);
    }
    int L = 0,R = blocks-2;

    while(L<=R){
        int l = L,r = R;
        int target = -1;
        while(l<=r){
            int mid = (l+r)/2;
            int low,high,pos;

            pos = (mid+1)*block;
            vector<int> arr = askme(pos);
            low = arr[0],high = arr[1];
            if(low + high == 0)
                return pos;
            if(low + high < cheap){
                bool chk = 0;
                arr = askme(pos-1);
                if(arr[0] + arr[1] < cheap || arr[0] - seen > 0)
                    chk = 1;
                if(arr[0] + arr[1] == 0)
                    return pos-1;
                if(chk){
                    target = mid;
                    r = mid-1;
                }
                else{
                    target = mid+1;
                    break;
                }
                continue;
            }
            if(low - seen > 0){
                target = mid;
                r = mid-1;
            }
            else
                l = mid+1;
        }
        if(target == -1)
            target = blocks-1;
        int ans = go(target);
        if(ans != -1)
            return ans;
        L = target+1;
    }
    int ans = go(blocks-1);
    if(ans != -1)
        return ans;
    assert(0);
    return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 7240 KB Output is correct
2 Correct 8 ms 7376 KB Output is correct
3 Correct 9 ms 7436 KB Output is correct
4 Correct 11 ms 7348 KB Output is correct
5 Correct 8 ms 7376 KB Output is correct
6 Correct 12 ms 7240 KB Output is correct
7 Correct 10 ms 7336 KB Output is correct
8 Correct 12 ms 7240 KB Output is correct
9 Correct 13 ms 7344 KB Output is correct
10 Correct 10 ms 7240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7352 KB Output is correct
2 Correct 8 ms 7420 KB Output is correct
3 Correct 8 ms 7360 KB Output is correct
4 Correct 12 ms 7340 KB Output is correct
5 Correct 9 ms 7348 KB Output is correct
6 Correct 11 ms 7348 KB Output is correct
7 Correct 12 ms 7240 KB Output is correct
8 Correct 12 ms 7336 KB Output is correct
9 Correct 13 ms 7240 KB Output is correct
10 Correct 12 ms 7240 KB Output is correct
11 Correct 17 ms 7240 KB Output is correct
12 Correct 10 ms 7328 KB Output is correct
13 Correct 26 ms 7340 KB Output is correct
14 Correct 20 ms 7240 KB Output is correct
15 Correct 31 ms 7360 KB Output is correct
16 Partially correct 98 ms 7776 KB Partially correct - number of queries: 7487
17 Correct 13 ms 7344 KB Output is correct
18 Partially correct 119 ms 7716 KB Partially correct - number of queries: 8702
19 Correct 9 ms 7352 KB Output is correct
20 Correct 19 ms 7416 KB Output is correct
21 Correct 61 ms 7360 KB Output is correct
22 Correct 21 ms 7316 KB Output is correct
23 Correct 10 ms 7240 KB Output is correct
24 Correct 11 ms 7240 KB Output is correct
25 Partially correct 50 ms 7400 KB Partially correct - number of queries: 5068
26 Correct 77 ms 7476 KB Output is correct
27 Correct 11 ms 7332 KB Output is correct
28 Partially correct 127 ms 7588 KB Partially correct - number of queries: 8117
29 Partially correct 96 ms 7500 KB Partially correct - number of queries: 6306
30 Partially correct 98 ms 7592 KB Partially correct - number of queries: 8634
31 Correct 13 ms 7240 KB Output is correct
32 Correct 19 ms 7352 KB Output is correct
33 Correct 6 ms 7348 KB Output is correct
34 Correct 48 ms 7340 KB Output is correct
35 Correct 13 ms 7332 KB Output is correct
36 Correct 35 ms 7364 KB Output is correct
37 Correct 16 ms 7336 KB Output is correct
38 Correct 16 ms 7332 KB Output is correct
39 Correct 50 ms 7412 KB Output is correct
40 Partially correct 105 ms 7592 KB Partially correct - number of queries: 7506
41 Partially correct 76 ms 7460 KB Partially correct - number of queries: 5416
42 Partially correct 71 ms 7492 KB Partially correct - number of queries: 5416
43 Correct 54 ms 7372 KB Output is correct
44 Correct 51 ms 7336 KB Output is correct
45 Correct 44 ms 7364 KB Output is correct
46 Correct 11 ms 7460 KB Output is correct
47 Correct 27 ms 7456 KB Output is correct
48 Partially correct 51 ms 7632 KB Partially correct - number of queries: 6575
49 Correct 18 ms 7240 KB Output is correct
50 Partially correct 82 ms 7488 KB Partially correct - number of queries: 8679
51 Correct 73 ms 7428 KB Output is correct
52 Correct 14 ms 7240 KB Output is correct
53 Correct 14 ms 7240 KB Output is correct
54 Correct 37 ms 7360 KB Output is correct
55 Correct 13 ms 7240 KB Output is correct
56 Partially correct 127 ms 7488 KB Partially correct - number of queries: 8714
57 Partially correct 75 ms 7460 KB Partially correct - number of queries: 6444
58 Partially correct 95 ms 7616 KB Partially correct - number of queries: 6521
59 Partially correct 60 ms 7460 KB Partially correct - number of queries: 5416
60 Partially correct 72 ms 7488 KB Partially correct - number of queries: 5058
61 Correct 14 ms 7240 KB Output is correct
62 Correct 12 ms 7240 KB Output is correct
63 Correct 15 ms 7240 KB Output is correct
64 Correct 16 ms 7328 KB Output is correct
65 Correct 8 ms 7348 KB Output is correct
66 Correct 15 ms 7340 KB Output is correct
67 Correct 15 ms 7340 KB Output is correct
68 Correct 23 ms 7360 KB Output is correct
69 Correct 19 ms 7368 KB Output is correct
70 Correct 13 ms 7332 KB Output is correct
71 Partially correct 53 ms 7596 KB Partially correct - number of queries: 8867
72 Correct 18 ms 7368 KB Output is correct
73 Partially correct 123 ms 7468 KB Partially correct - number of queries: 8743
74 Partially correct 100 ms 7624 KB Partially correct - number of queries: 8787
75 Correct 14 ms 7372 KB Output is correct
76 Partially correct 109 ms 7696 KB Partially correct - number of queries: 7688
77 Partially correct 63 ms 7596 KB Partially correct - number of queries: 8814
78 Correct 14 ms 7384 KB Output is correct
79 Correct 40 ms 7672 KB Output is correct
80 Partially correct 139 ms 7644 KB Partially correct - number of queries: 8834
81 Partially correct 103 ms 7616 KB Partially correct - number of queries: 8855
82 Partially correct 61 ms 7596 KB Partially correct - number of queries: 8784
83 Correct 15 ms 7240 KB Output is correct
84 Partially correct 71 ms 7500 KB Partially correct - number of queries: 7321
85 Partially correct 126 ms 7600 KB Partially correct - number of queries: 8850
86 Correct 17 ms 7368 KB Output is correct
87 Correct 14 ms 7352 KB Output is correct
88 Correct 24 ms 7368 KB Output is correct
89 Correct 19 ms 7360 KB Output is correct
90 Correct 14 ms 7356 KB Output is correct
91 Correct 19 ms 7364 KB Output is correct
92 Correct 22 ms 7360 KB Output is correct
93 Correct 29 ms 7368 KB Output is correct
94 Correct 20 ms 7368 KB Output is correct
95 Correct 17 ms 7368 KB Output is correct
96 Correct 28 ms 7368 KB Output is correct
97 Correct 22 ms 7368 KB Output is correct