답안 #70353

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70353 2018-08-22T16:46:34 Z evpipis 커다란 상품 (IOI17_prize) C++11
90 / 100
100 ms 2236 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;

//#define TEST

#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;

const int len = 2e5+5;
ii arr[len];
int pos, n, sum;

/*vector<int> ask(int i) {
    fprintf(fout, "A %d\n", i);
    fflush(fout);
    vector<int> result(2);
    if (fscanf(fin, "%d %d", &result[0], &result[1]) != 2) {
        cerr << "tester error" << endl;
        cerr << "could not read query response" << endl;
        exit(0);
    }
    if (result[0] < 0) {
        exit(0);
    }
    return result;
}*/

#ifdef TEST
vector<int> ask(int i){
    printf("ask %d\n", i), fflush(stdout);
    int a, b;
    scanf("%d %d", &a, &b);
    vector<int> temp;
    temp.pb(a), temp.pb(b);
    return temp;
}
#endif

ii val(int i){
    if (arr[i] != mp(-1, -1))
        return arr[i];

    vector<int> temp = ask(i);
    return arr[i] = mp(temp[0], temp[1]);
}

int bs(){
    int l = pos, r = n-1, ans;
    while (l <= r){
        int mid = (l+r)/2;
        if (val(mid) == val(pos)){
            ans = mid;
            l = mid+1;
        }
        else
            r = mid-1;
    }

    return ans;
}

int find_best(int N){
    n = N, sum = 0, pos = 0;
    for (int i = 0; i < n; i++)
        arr[i] = mp(-1, -1);

    for (int i = 0; i < min(481, n); i++)
        sum = max(sum, val(i).fi + val(i).se);

    while (pos < n){
        if (val(pos).fi+val(pos).se != sum){
            if (val(pos) == mp(0, 0))
                return pos;
            pos++;
        }
        else{
            pos = bs() + 1;
        }
    }

    return 0;
}

#ifdef TEST
int main(int argc, char **argv) {
    int n;
    scanf("%d", &n);
    printf("%d\n", find_best(n));
    return 0;
}
#endif

Compilation message

prize.cpp: In function 'int bs()':
prize.cpp:64:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
     return ans;
            ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1912 KB Output is correct
2 Correct 8 ms 2016 KB Output is correct
3 Correct 11 ms 2056 KB Output is correct
4 Correct 7 ms 2056 KB Output is correct
5 Correct 5 ms 2056 KB Output is correct
6 Correct 11 ms 2056 KB Output is correct
7 Correct 10 ms 2056 KB Output is correct
8 Correct 10 ms 2056 KB Output is correct
9 Correct 7 ms 2056 KB Output is correct
10 Correct 7 ms 2084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2108 KB Output is correct
2 Correct 10 ms 2108 KB Output is correct
3 Correct 7 ms 2108 KB Output is correct
4 Correct 6 ms 2108 KB Output is correct
5 Correct 11 ms 2108 KB Output is correct
6 Correct 11 ms 2108 KB Output is correct
7 Correct 11 ms 2108 KB Output is correct
8 Correct 10 ms 2108 KB Output is correct
9 Correct 6 ms 2108 KB Output is correct
10 Correct 10 ms 2108 KB Output is correct
11 Correct 11 ms 2108 KB Output is correct
12 Correct 5 ms 2108 KB Output is correct
13 Correct 10 ms 2108 KB Output is correct
14 Correct 11 ms 2108 KB Output is correct
15 Correct 29 ms 2108 KB Output is correct
16 Partially correct 65 ms 2108 KB Partially correct - number of queries: 7200
17 Correct 8 ms 2108 KB Output is correct
18 Partially correct 90 ms 2108 KB Partially correct - number of queries: 8360
19 Correct 10 ms 2108 KB Output is correct
20 Correct 33 ms 2108 KB Output is correct
21 Correct 34 ms 2116 KB Output is correct
22 Correct 18 ms 2116 KB Output is correct
23 Correct 12 ms 2116 KB Output is correct
24 Correct 8 ms 2116 KB Output is correct
25 Correct 61 ms 2116 KB Output is correct
26 Correct 57 ms 2116 KB Output is correct
27 Correct 12 ms 2116 KB Output is correct
28 Partially correct 71 ms 2116 KB Partially correct - number of queries: 7884
29 Partially correct 71 ms 2116 KB Partially correct - number of queries: 6124
30 Partially correct 45 ms 2116 KB Partially correct - number of queries: 8289
31 Correct 7 ms 2116 KB Output is correct
32 Correct 23 ms 2116 KB Output is correct
33 Correct 4 ms 2116 KB Output is correct
34 Correct 38 ms 2116 KB Output is correct
35 Correct 8 ms 2116 KB Output is correct
36 Correct 25 ms 2116 KB Output is correct
37 Correct 9 ms 2116 KB Output is correct
38 Correct 10 ms 2116 KB Output is correct
39 Correct 68 ms 2116 KB Output is correct
40 Partially correct 78 ms 2116 KB Partially correct - number of queries: 7165
41 Partially correct 25 ms 2116 KB Partially correct - number of queries: 5220
42 Partially correct 54 ms 2116 KB Partially correct - number of queries: 5220
43 Correct 76 ms 2116 KB Output is correct
44 Correct 22 ms 2116 KB Output is correct
45 Correct 56 ms 2116 KB Output is correct
46 Correct 11 ms 2116 KB Output is correct
47 Correct 66 ms 2116 KB Output is correct
48 Partially correct 95 ms 2116 KB Partially correct - number of queries: 6316
49 Correct 19 ms 2116 KB Output is correct
50 Partially correct 87 ms 2120 KB Partially correct - number of queries: 8361
51 Correct 41 ms 2120 KB Output is correct
52 Correct 10 ms 2120 KB Output is correct
53 Correct 10 ms 2120 KB Output is correct
54 Correct 34 ms 2120 KB Output is correct
55 Correct 8 ms 2120 KB Output is correct
56 Partially correct 49 ms 2120 KB Partially correct - number of queries: 8356
57 Partially correct 41 ms 2120 KB Partially correct - number of queries: 6220
58 Partially correct 75 ms 2120 KB Partially correct - number of queries: 6302
59 Partially correct 59 ms 2120 KB Partially correct - number of queries: 5217
60 Correct 48 ms 2120 KB Output is correct
61 Correct 7 ms 2120 KB Output is correct
62 Correct 9 ms 2120 KB Output is correct
63 Correct 15 ms 2120 KB Output is correct
64 Correct 6 ms 2120 KB Output is correct
65 Correct 7 ms 2120 KB Output is correct
66 Correct 11 ms 2236 KB Output is correct
67 Correct 9 ms 2236 KB Output is correct
68 Correct 6 ms 2236 KB Output is correct
69 Correct 18 ms 2236 KB Output is correct
70 Correct 12 ms 2236 KB Output is correct
71 Partially correct 54 ms 2236 KB Partially correct - number of queries: 8251
72 Correct 11 ms 2236 KB Output is correct
73 Partially correct 86 ms 2236 KB Partially correct - number of queries: 8140
74 Partially correct 100 ms 2236 KB Partially correct - number of queries: 8200
75 Correct 9 ms 2236 KB Output is correct
76 Partially correct 66 ms 2236 KB Partially correct - number of queries: 7086
77 Partially correct 82 ms 2236 KB Partially correct - number of queries: 8392
78 Correct 8 ms 2236 KB Output is correct
79 Correct 36 ms 2236 KB Output is correct
80 Partially correct 91 ms 2236 KB Partially correct - number of queries: 8393
81 Partially correct 46 ms 2236 KB Partially correct - number of queries: 8383
82 Partially correct 54 ms 2236 KB Partially correct - number of queries: 8328
83 Correct 9 ms 2236 KB Output is correct
84 Partially correct 63 ms 2236 KB Partially correct - number of queries: 6950
85 Partially correct 93 ms 2236 KB Partially correct - number of queries: 8404
86 Correct 8 ms 2236 KB Output is correct
87 Correct 7 ms 2236 KB Output is correct
88 Correct 8 ms 2236 KB Output is correct
89 Correct 7 ms 2236 KB Output is correct
90 Correct 7 ms 2236 KB Output is correct
91 Correct 8 ms 2236 KB Output is correct
92 Correct 6 ms 2236 KB Output is correct
93 Correct 13 ms 2236 KB Output is correct
94 Correct 7 ms 2236 KB Output is correct
95 Correct 13 ms 2236 KB Output is correct
96 Correct 10 ms 2236 KB Output is correct
97 Correct 9 ms 2236 KB Output is correct