Submission #311187

# Submission time Handle Problem Language Result Execution time Memory
311187 2020-10-09T15:26:11 Z aZvezda The Big Prize (IOI17_prize) C++14
96.41 / 100
56 ms 952 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), grNow = query(group);
        if(now[0] + now[1] != bigSum) {
            if(now[0] + now[1] == 0) {
                return i;
            }
            i ++;
            continue;
        }
        if(!eval(now, grNow, 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;}
      |                        ~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 10 ms 384 KB Output is correct
4 Correct 10 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 432 KB Output is correct
8 Correct 8 ms 384 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 512 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 9 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 560 KB Output is correct
8 Correct 8 ms 384 KB Output is correct
9 Correct 8 ms 368 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 10 ms 376 KB Output is correct
12 Correct 7 ms 376 KB Output is correct
13 Correct 11 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 13 ms 384 KB Output is correct
16 Correct 47 ms 760 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Partially correct 31 ms 936 KB Partially correct - number of queries: 5332
19 Correct 3 ms 412 KB Output is correct
20 Correct 14 ms 508 KB Output is correct
21 Correct 18 ms 644 KB Output is correct
22 Correct 8 ms 384 KB Output is correct
23 Correct 7 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 29 ms 632 KB Output is correct
26 Correct 29 ms 632 KB Output is correct
27 Correct 7 ms 364 KB Output is correct
28 Correct 45 ms 888 KB Output is correct
29 Correct 37 ms 760 KB Output is correct
30 Partially correct 56 ms 888 KB Partially correct - number of queries: 5261
31 Correct 6 ms 384 KB Output is correct
32 Correct 10 ms 384 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 21 ms 504 KB Output is correct
35 Correct 9 ms 384 KB Output is correct
36 Correct 9 ms 540 KB Output is correct
37 Correct 7 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 20 ms 668 KB Output is correct
40 Correct 43 ms 888 KB Output is correct
41 Correct 35 ms 632 KB Output is correct
42 Correct 42 ms 632 KB Output is correct
43 Correct 27 ms 632 KB Output is correct
44 Correct 21 ms 504 KB Output is correct
45 Correct 17 ms 504 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 16 ms 632 KB Output is correct
48 Correct 38 ms 792 KB Output is correct
49 Correct 7 ms 360 KB Output is correct
50 Partially correct 46 ms 888 KB Partially correct - number of queries: 5332
51 Correct 22 ms 504 KB Output is correct
52 Correct 7 ms 384 KB Output is correct
53 Correct 10 ms 384 KB Output is correct
54 Correct 25 ms 632 KB Output is correct
55 Correct 7 ms 356 KB Output is correct
56 Partially correct 32 ms 952 KB Partially correct - number of queries: 5322
57 Correct 37 ms 760 KB Output is correct
58 Correct 35 ms 760 KB Output is correct
59 Correct 32 ms 632 KB Output is correct
60 Correct 18 ms 692 KB Output is correct
61 Correct 12 ms 384 KB Output is correct
62 Correct 7 ms 384 KB Output is correct
63 Correct 6 ms 492 KB Output is correct
64 Correct 11 ms 384 KB Output is correct
65 Correct 12 ms 384 KB Output is correct
66 Correct 8 ms 504 KB Output is correct
67 Correct 13 ms 376 KB Output is correct
68 Correct 10 ms 376 KB Output is correct
69 Correct 10 ms 612 KB Output is correct
70 Correct 11 ms 376 KB Output is correct
71 Partially correct 55 ms 892 KB Partially correct - number of queries: 5119
72 Correct 11 ms 384 KB Output is correct
73 Partially correct 40 ms 888 KB Partially correct - number of queries: 5063
74 Partially correct 42 ms 888 KB Partially correct - number of queries: 5087
75 Correct 6 ms 384 KB Output is correct
76 Correct 32 ms 940 KB Output is correct
77 Partially correct 55 ms 888 KB Partially correct - number of queries: 5350
78 Correct 8 ms 384 KB Output is correct
79 Correct 29 ms 632 KB Output is correct
80 Partially correct 48 ms 888 KB Partially correct - number of queries: 5359
81 Partially correct 44 ms 888 KB Partially correct - number of queries: 5345
82 Partially correct 54 ms 892 KB Partially correct - number of queries: 5319
83 Correct 7 ms 384 KB Output is correct
84 Correct 47 ms 760 KB Output is correct
85 Partially correct 53 ms 892 KB Partially correct - number of queries: 5345
86 Correct 5 ms 384 KB Output is correct
87 Correct 5 ms 384 KB Output is correct
88 Correct 5 ms 384 KB Output is correct
89 Correct 6 ms 384 KB Output is correct
90 Correct 4 ms 368 KB Output is correct
91 Correct 5 ms 512 KB Output is correct
92 Correct 4 ms 384 KB Output is correct
93 Correct 39 ms 940 KB Output is correct
94 Partially correct 48 ms 888 KB Partially correct - number of queries: 5095
95 Partially correct 48 ms 888 KB Partially correct - number of queries: 5102
96 Partially correct 44 ms 888 KB Partially correct - number of queries: 5067
97 Correct 39 ms 760 KB Output is correct