답안 #311192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
311192 2020-10-09T15:32:57 Z aZvezda 커다란 상품 (IOI17_prize) C++14
96.41 / 100
74 ms 1016 KB
#include "prize.h"
#include <vector>

int find_best(int n);
std::vector<int> ask(int i);

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#define out(x) "{" << (#x) << ": " << x << "} "

map<int, vector<int> > prec;

vector<int> query(int x) {
    if(prec.find(x) != prec.end()) {
        return prec[x];
    } else {
        return prec[x] = ask(x);
    }
}

bool eval(vector<int> curr, vector<int> nxt, int bigSum) {
    if(nxt[0] + nxt[1] != bigSum) {
        return true;
    } else if(nxt[0] != curr[0]) {
        return true;
    } else {
        return false;
    }
}

int find_best(int n) {
    prec.clear();
    int sqr = sqrt(n), group;
    int bigSum = 0;
    for(int i = n - 1; i > 0; i -= sqr) {
        auto now = query(i);
        chkmax(bigSum, now[0] + now[1]);
        group = i;
        //cout << i << " " << now[0] << " " << now[1] << endl;
    }
    for(int i = 0; i < n;) {
        if(i > group) {group += sqr;}
        //cout << i << endl;
        auto now = query(i);
        if(now[0] + now[1] != bigSum) {
            if(now[0] + now[1] == 0) {
                return i;
            }
            i ++;
            continue;
        }
        if(!eval(now, query(group), bigSum)) {
            i = group + 1;
            continue;
        }
        int l = i, r = group;
        while(l < r - 1) {
            int m = (l + r) / 2ll;
            if(eval(now, query(m), bigSum)) {
                r = m;
            } else {
                l = m;
            }
        }
        i = r; continue;
    }
    for(auto it : prec) {
        if(it.second[0] + it.second[1] == 0) {
            return it.first;
        }
    }
    return -1;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:51:30: warning: 'group' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |         if(i > group) {group += sqr;}
      |                        ~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 4 ms 440 KB Output is correct
4 Correct 7 ms 364 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 10 ms 416 KB Output is correct
8 Correct 8 ms 384 KB Output is correct
9 Correct 4 ms 448 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 10 ms 376 KB Output is correct
3 Correct 10 ms 376 KB Output is correct
4 Correct 10 ms 384 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 9 ms 384 KB Output is correct
8 Correct 10 ms 384 KB Output is correct
9 Correct 4 ms 440 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 11 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 7 ms 504 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 11 ms 376 KB Output is correct
16 Correct 39 ms 760 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Partially correct 31 ms 952 KB Partially correct - number of queries: 5332
19 Correct 6 ms 384 KB Output is correct
20 Correct 14 ms 512 KB Output is correct
21 Correct 19 ms 536 KB Output is correct
22 Correct 8 ms 376 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 4 ms 376 KB Output is correct
25 Correct 42 ms 624 KB Output is correct
26 Correct 29 ms 632 KB Output is correct
27 Correct 9 ms 384 KB Output is correct
28 Correct 62 ms 892 KB Output is correct
29 Correct 48 ms 760 KB Output is correct
30 Partially correct 57 ms 1016 KB Partially correct - number of queries: 5261
31 Correct 5 ms 376 KB Output is correct
32 Correct 9 ms 376 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 27 ms 504 KB Output is correct
35 Correct 10 ms 696 KB Output is correct
36 Correct 10 ms 548 KB Output is correct
37 Correct 9 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 18 ms 608 KB Output is correct
40 Correct 65 ms 760 KB Output is correct
41 Correct 43 ms 632 KB Output is correct
42 Correct 19 ms 728 KB Output is correct
43 Correct 36 ms 632 KB Output is correct
44 Correct 26 ms 504 KB Output is correct
45 Correct 19 ms 504 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 16 ms 652 KB Output is correct
48 Correct 24 ms 744 KB Output is correct
49 Correct 9 ms 384 KB Output is correct
50 Partially correct 51 ms 888 KB Partially correct - number of queries: 5332
51 Correct 25 ms 504 KB Output is correct
52 Correct 3 ms 412 KB Output is correct
53 Correct 10 ms 384 KB Output is correct
54 Correct 32 ms 632 KB Output is correct
55 Correct 8 ms 376 KB Output is correct
56 Partially correct 71 ms 908 KB Partially correct - number of queries: 5322
57 Correct 34 ms 760 KB Output is correct
58 Correct 53 ms 760 KB Output is correct
59 Correct 33 ms 768 KB Output is correct
60 Correct 32 ms 632 KB Output is correct
61 Correct 9 ms 384 KB Output is correct
62 Correct 5 ms 376 KB Output is correct
63 Correct 10 ms 384 KB Output is correct
64 Correct 8 ms 384 KB Output is correct
65 Correct 10 ms 384 KB Output is correct
66 Correct 14 ms 504 KB Output is correct
67 Correct 11 ms 384 KB Output is correct
68 Correct 9 ms 376 KB Output is correct
69 Correct 17 ms 504 KB Output is correct
70 Correct 7 ms 376 KB Output is correct
71 Partially correct 66 ms 924 KB Partially correct - number of queries: 5119
72 Correct 8 ms 384 KB Output is correct
73 Partially correct 54 ms 888 KB Partially correct - number of queries: 5063
74 Partially correct 51 ms 888 KB Partially correct - number of queries: 5087
75 Correct 7 ms 384 KB Output is correct
76 Correct 32 ms 852 KB Output is correct
77 Partially correct 74 ms 888 KB Partially correct - number of queries: 5350
78 Correct 11 ms 384 KB Output is correct
79 Correct 39 ms 632 KB Output is correct
80 Partially correct 73 ms 888 KB Partially correct - number of queries: 5359
81 Partially correct 73 ms 888 KB Partially correct - number of queries: 5345
82 Partially correct 58 ms 888 KB Partially correct - number of queries: 5319
83 Correct 8 ms 384 KB Output is correct
84 Correct 59 ms 760 KB Output is correct
85 Partially correct 73 ms 888 KB Partially correct - number of queries: 5345
86 Correct 7 ms 384 KB Output is correct
87 Correct 6 ms 384 KB Output is correct
88 Correct 6 ms 384 KB Output is correct
89 Correct 7 ms 384 KB Output is correct
90 Correct 6 ms 384 KB Output is correct
91 Correct 5 ms 384 KB Output is correct
92 Correct 5 ms 384 KB Output is correct
93 Correct 47 ms 892 KB Output is correct
94 Partially correct 49 ms 888 KB Partially correct - number of queries: 5095
95 Partially correct 63 ms 888 KB Partially correct - number of queries: 5102
96 Partially correct 54 ms 888 KB Partially correct - number of queries: 5067
97 Correct 49 ms 864 KB Output is correct