답안 #390593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
390593 2021-04-16T10:53:54 Z faresbasbs 커다란 상품 (IOI17_prize) C++14
98.95 / 100
71 ms 5296 KB
#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
vector<int> p[200001];

vector<int> askk(int pos){
    if(p[pos].size()){
        return p[pos];
    }
    return p[pos] = ask(pos);
}

int find_best(int n){
    int sum = 0;
    for(int i = 0 ; i < 447 ; i += 1){
        int a = rand()%n;
        vector<int> v = askk(a);
        sum = max(sum,v[0]+v[1]);
        if(v[0]+v[1] == 0){
            return a;
        }
    }
    vector<pair<int,vector<int>>> v;
    int p = 0;
    while(p < n){
        while(p < n){
            vector<int> f = askk(p);
            if(f[0]+f[1] == sum){
                v.push_back({p,f});
                break;
            }else{
                if(f[0]+f[1] == 0){
                    return p;
                }
                p += 1;
            }
        }
        p += 502;
    }
    v.push_back({n,{sum,0}});
    for(int i = 0 ; i+1 < v.size() ; i += 1){
        while(v[i+1].second[0] != v[i].second[0]){
            int first = v[i].first , last = v[i+1].first;
            while(last-first > 1){
                int mid = (first+last)/2;
                vector<int> f = askk(mid);
                if(f[0]+f[1] == 0){
                    return mid;
                }
                if(f[0]+f[1] == sum && f[0] == v[i].second[0]){
                    first = mid;
                }else{
                    last = mid;
                }
            }
            if(v[i+1].second[0] == v[i].second[0]+1){
                break;
            }
            vector<int> f;
            for(int j = first+2 ; j < n ; j += 1){
                f = askk(j);
                if(f[0]+f[1] == 0){
                    return j;
                }
                if(f[0]+f[1] == sum){
                    v[i] = {j,f};
                    break;
                }
            }
        }
    }
}

/*int main(){
    cout << find_best(8) << endl;
}*/

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:41:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i = 0 ; i+1 < v.size() ; i += 1){
      |                     ~~~~^~~~~~~~~~
prize.cpp:23:35: warning: control reaches end of non-void function [-Wreturn-type]
   23 |     vector<pair<int,vector<int>>> v;
      |                                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 4936 KB Output is correct
2 Correct 10 ms 4936 KB Output is correct
3 Correct 8 ms 5100 KB Output is correct
4 Correct 14 ms 4936 KB Output is correct
5 Correct 14 ms 4992 KB Output is correct
6 Correct 8 ms 4936 KB Output is correct
7 Correct 8 ms 5008 KB Output is correct
8 Correct 13 ms 4988 KB Output is correct
9 Correct 8 ms 5012 KB Output is correct
10 Correct 12 ms 4936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5100 KB Output is correct
2 Correct 14 ms 5112 KB Output is correct
3 Correct 13 ms 4936 KB Output is correct
4 Correct 19 ms 4980 KB Output is correct
5 Correct 15 ms 4988 KB Output is correct
6 Correct 9 ms 4936 KB Output is correct
7 Correct 14 ms 4940 KB Output is correct
8 Correct 12 ms 4936 KB Output is correct
9 Correct 15 ms 4936 KB Output is correct
10 Correct 12 ms 4936 KB Output is correct
11 Correct 12 ms 4984 KB Output is correct
12 Correct 11 ms 4940 KB Output is correct
13 Correct 19 ms 4936 KB Output is correct
14 Correct 14 ms 4936 KB Output is correct
15 Correct 26 ms 4936 KB Output is correct
16 Correct 6 ms 4936 KB Output is correct
17 Correct 8 ms 5000 KB Output is correct
18 Partially correct 65 ms 5056 KB Partially correct - number of queries: 5105
19 Correct 13 ms 4972 KB Output is correct
20 Correct 26 ms 5004 KB Output is correct
21 Correct 34 ms 4988 KB Output is correct
22 Correct 10 ms 5028 KB Output is correct
23 Correct 15 ms 4984 KB Output is correct
24 Correct 15 ms 4980 KB Output is correct
25 Correct 48 ms 5096 KB Output is correct
26 Correct 20 ms 5180 KB Output is correct
27 Correct 8 ms 5024 KB Output is correct
28 Correct 48 ms 5056 KB Output is correct
29 Correct 49 ms 5056 KB Output is correct
30 Partially correct 54 ms 5056 KB Partially correct - number of queries: 5080
31 Correct 7 ms 5004 KB Output is correct
32 Correct 15 ms 4984 KB Output is correct
33 Correct 4 ms 4936 KB Output is correct
34 Correct 32 ms 4984 KB Output is correct
35 Correct 15 ms 4936 KB Output is correct
36 Correct 15 ms 5072 KB Output is correct
37 Correct 9 ms 5012 KB Output is correct
38 Correct 13 ms 5056 KB Output is correct
39 Correct 21 ms 5172 KB Output is correct
40 Correct 25 ms 5136 KB Output is correct
41 Correct 20 ms 5100 KB Output is correct
42 Correct 44 ms 5056 KB Output is correct
43 Correct 23 ms 5296 KB Output is correct
44 Correct 25 ms 5052 KB Output is correct
45 Correct 32 ms 4968 KB Output is correct
46 Correct 16 ms 4984 KB Output is correct
47 Correct 17 ms 5172 KB Output is correct
48 Correct 49 ms 5104 KB Output is correct
49 Correct 12 ms 5028 KB Output is correct
50 Partially correct 71 ms 5040 KB Partially correct - number of queries: 5103
51 Correct 24 ms 5004 KB Output is correct
52 Correct 15 ms 4992 KB Output is correct
53 Correct 20 ms 5004 KB Output is correct
54 Correct 39 ms 4992 KB Output is correct
55 Correct 13 ms 4936 KB Output is correct
56 Partially correct 65 ms 5208 KB Partially correct - number of queries: 5104
57 Correct 55 ms 5112 KB Output is correct
58 Correct 46 ms 5072 KB Output is correct
59 Correct 19 ms 5192 KB Output is correct
60 Correct 43 ms 5092 KB Output is correct
61 Correct 16 ms 4988 KB Output is correct
62 Correct 16 ms 4996 KB Output is correct
63 Correct 15 ms 4980 KB Output is correct
64 Correct 14 ms 5056 KB Output is correct
65 Correct 10 ms 4976 KB Output is correct
66 Correct 16 ms 4980 KB Output is correct
67 Correct 12 ms 4980 KB Output is correct
68 Correct 13 ms 5064 KB Output is correct
69 Correct 11 ms 5128 KB Output is correct
70 Correct 18 ms 4980 KB Output is correct
71 Partially correct 65 ms 5148 KB Partially correct - number of queries: 5038
72 Correct 15 ms 4936 KB Output is correct
73 Correct 63 ms 5108 KB Output is correct
74 Partially correct 70 ms 5056 KB Partially correct - number of queries: 5003
75 Correct 14 ms 4936 KB Output is correct
76 Correct 48 ms 5128 KB Output is correct
77 Partially correct 29 ms 5080 KB Partially correct - number of queries: 5074
78 Correct 9 ms 5048 KB Output is correct
79 Correct 28 ms 5012 KB Output is correct
80 Partially correct 50 ms 5292 KB Partially correct - number of queries: 5078
81 Partially correct 61 ms 5036 KB Partially correct - number of queries: 5065
82 Partially correct 71 ms 5040 KB Partially correct - number of queries: 5033
83 Correct 8 ms 5064 KB Output is correct
84 Correct 51 ms 5056 KB Output is correct
85 Partially correct 51 ms 5052 KB Partially correct - number of queries: 5063
86 Correct 44 ms 5104 KB Output is correct
87 Correct 15 ms 4936 KB Output is correct
88 Correct 34 ms 5184 KB Output is correct
89 Correct 21 ms 5004 KB Output is correct
90 Correct 14 ms 4936 KB Output is correct
91 Correct 19 ms 5056 KB Output is correct
92 Correct 54 ms 5044 KB Output is correct
93 Correct 31 ms 5160 KB Output is correct
94 Correct 42 ms 5148 KB Output is correct
95 Correct 40 ms 5136 KB Output is correct
96 Correct 49 ms 5052 KB Output is correct
97 Correct 41 ms 5012 KB Output is correct