Submission #946306

# Submission time Handle Problem Language Result Execution time Memory
946306 2024-03-14T13:37:17 Z Pikachu The Big Prize (IOI17_prize) C++17
100 / 100
41 ms 3532 KB
#include <bits/stdc++.h>
#include "prize.h"

using namespace std;

template<typename T>
inline bool maxi(T &x, const T &val)
{
    if (x < val) return x = val, true;
    return false;
}

template<typename T>
inline bool mini(T &x, const T &val)
{
    if (x > val) return x = val, true;
    return false;
}

map<int,pair<int,int> > mp[500];

int RandInt(int l, int r)
{
    int ans = 0;
    for (int i = 0; i < 2; i++) {
        ans = (ans << 15) | (rand() & ((1 << 15) - 1));
    }
    return ans % (r - l + 1) + l;
}

const int maxn = 2e5 + 10;
pair<int,int> dak[maxn];
bool done;
int res;
int cntask;

pair<int,int> myask(int x)
{
    if (done) return make_pair(-1, -1);
    if (dak[x].first != -1) return dak[x];
    // cntask++;
    // if (cntask > 10000) assert(false);
    vector<int> tmp = ask(x - 1);
    if (tmp[0] + tmp[1] == 0) {
        res = x - 1;
        done = true;
    }
    dak[x] = make_pair(tmp[0], tmp[1]);
    mp[tmp[0] + tmp[1]][x] = dak[x];
    return dak[x];
}

int find_best(int n) 
{
    srand(time(0));
    memset(dak, -1, sizeof dak);
    int maxx = 0;
    int test = 100;
    while (test--) {
        int x = RandInt(1, n);
        pair<int,int> tmp = myask(x);
        maxi(maxx, tmp.first + tmp.second);
    }
    int cur = 1;
    while (!done) {
        pair<int,int> tmp = myask(cur);
        if (tmp.first + tmp.second != maxx) cur++;
        else break;
    }
    int old = cur, cntold = 0;
    while (!done) {
        if (cur == old) {
            cntold++;
            assert(cntold <= 20);
        }
        else {
            old = cur;
            cntold = 0;
        }
        if (myask(cur).second == 0) break;
        if (myask(cur).second == n - cur) {
            for (int i = cur + 1; i <= n; i++) {
                myask(i);
            }
            break;
        }
        auto it = mp[maxx].upper_bound(cur);
        int nex = n;
        if (it != mp[maxx].end()) {
            nex = it -> first;
            if (it -> second.second == mp[maxx][cur].second) {
                cur = nex;
                continue;
            }
        }
        int mid = (cur + nex) >> 1;
        while (!done) {
            pair<int,int> tmp = myask(mid);
            if (tmp.first + tmp.second != maxx) mid--;
            else break;
        }
        if (mid == cur) {
            mid = (cur + nex) >> 1;
            while (!done) {
                pair<int,int> tmp = myask(mid);
                if (tmp.first + tmp.second != maxx) mid++;
                else break;
            }
            if (mid == nex) {
                cur = nex;
            }
            else {
                cur = mid;
            }
            continue;
        }
    }
    return res;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:56:31: warning: 'void* memset(void*, int, size_t)' writing to an object of type 'struct std::pair<int, int>' with no trivial copy-assignment [-Wclass-memaccess]
   56 |     memset(dak, -1, sizeof dak);
      |                               ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from prize.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<int, int>' declared here
  211 |     struct pair
      |            ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2032 KB Output is correct
2 Correct 1 ms 2028 KB Output is correct
3 Correct 2 ms 2036 KB Output is correct
4 Correct 2 ms 2032 KB Output is correct
5 Correct 1 ms 2028 KB Output is correct
6 Correct 1 ms 2028 KB Output is correct
7 Correct 1 ms 2032 KB Output is correct
8 Correct 2 ms 2236 KB Output is correct
9 Correct 2 ms 2032 KB Output is correct
10 Correct 2 ms 2032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2036 KB Output is correct
2 Correct 1 ms 2032 KB Output is correct
3 Correct 1 ms 2028 KB Output is correct
4 Correct 1 ms 2032 KB Output is correct
5 Correct 1 ms 2024 KB Output is correct
6 Correct 1 ms 2032 KB Output is correct
7 Correct 2 ms 2032 KB Output is correct
8 Correct 2 ms 2028 KB Output is correct
9 Correct 1 ms 2028 KB Output is correct
10 Correct 2 ms 2028 KB Output is correct
11 Correct 3 ms 2288 KB Output is correct
12 Correct 1 ms 2032 KB Output is correct
13 Correct 4 ms 2044 KB Output is correct
14 Correct 2 ms 2028 KB Output is correct
15 Correct 4 ms 2560 KB Output is correct
16 Correct 19 ms 3224 KB Output is correct
17 Correct 2 ms 2032 KB Output is correct
18 Correct 41 ms 2516 KB Output is correct
19 Correct 2 ms 2028 KB Output is correct
20 Correct 6 ms 2856 KB Output is correct
21 Correct 10 ms 2620 KB Output is correct
22 Correct 4 ms 2032 KB Output is correct
23 Correct 2 ms 2036 KB Output is correct
24 Correct 1 ms 2036 KB Output is correct
25 Correct 15 ms 2352 KB Output is correct
26 Correct 13 ms 2312 KB Output is correct
27 Correct 2 ms 2036 KB Output is correct
28 Correct 20 ms 3228 KB Output is correct
29 Correct 20 ms 2860 KB Output is correct
30 Correct 24 ms 3236 KB Output is correct
31 Correct 1 ms 2028 KB Output is correct
32 Correct 3 ms 2556 KB Output is correct
33 Correct 1 ms 2036 KB Output is correct
34 Correct 8 ms 2292 KB Output is correct
35 Correct 2 ms 2028 KB Output is correct
36 Correct 5 ms 2580 KB Output is correct
37 Correct 2 ms 2032 KB Output is correct
38 Correct 1 ms 2032 KB Output is correct
39 Correct 10 ms 2564 KB Output is correct
40 Correct 20 ms 3360 KB Output is correct
41 Correct 13 ms 2900 KB Output is correct
42 Correct 11 ms 2828 KB Output is correct
43 Correct 14 ms 2184 KB Output is correct
44 Correct 9 ms 2356 KB Output is correct
45 Correct 7 ms 2588 KB Output is correct
46 Correct 1 ms 2036 KB Output is correct
47 Correct 10 ms 3076 KB Output is correct
48 Correct 18 ms 3348 KB Output is correct
49 Correct 3 ms 2136 KB Output is correct
50 Correct 21 ms 2736 KB Output is correct
51 Correct 11 ms 2560 KB Output is correct
52 Correct 1 ms 2032 KB Output is correct
53 Correct 2 ms 2392 KB Output is correct
54 Correct 12 ms 2552 KB Output is correct
55 Correct 1 ms 2032 KB Output is correct
56 Correct 24 ms 3532 KB Output is correct
57 Correct 17 ms 2824 KB Output is correct
58 Correct 16 ms 2628 KB Output is correct
59 Correct 12 ms 3140 KB Output is correct
60 Correct 11 ms 2888 KB Output is correct
61 Correct 2 ms 2284 KB Output is correct
62 Correct 1 ms 2028 KB Output is correct
63 Correct 2 ms 2024 KB Output is correct
64 Correct 2 ms 2032 KB Output is correct
65 Correct 2 ms 2028 KB Output is correct
66 Correct 4 ms 2296 KB Output is correct
67 Correct 1 ms 2028 KB Output is correct
68 Correct 3 ms 2300 KB Output is correct
69 Correct 3 ms 2300 KB Output is correct
70 Correct 1 ms 2032 KB Output is correct
71 Correct 22 ms 2944 KB Output is correct
72 Correct 3 ms 2056 KB Output is correct
73 Correct 31 ms 3012 KB Output is correct
74 Correct 23 ms 3412 KB Output is correct
75 Correct 2 ms 2040 KB Output is correct
76 Correct 19 ms 2484 KB Output is correct
77 Correct 36 ms 2616 KB Output is correct
78 Correct 4 ms 2540 KB Output is correct
79 Correct 16 ms 2652 KB Output is correct
80 Correct 27 ms 3496 KB Output is correct
81 Correct 26 ms 2620 KB Output is correct
82 Correct 23 ms 3472 KB Output is correct
83 Correct 2 ms 2280 KB Output is correct
84 Correct 19 ms 2536 KB Output is correct
85 Correct 33 ms 2728 KB Output is correct
86 Correct 14 ms 3052 KB Output is correct
87 Correct 2 ms 2296 KB Output is correct
88 Correct 16 ms 2536 KB Output is correct
89 Correct 13 ms 3084 KB Output is correct
90 Correct 2 ms 2284 KB Output is correct
91 Correct 13 ms 2572 KB Output is correct
92 Correct 6 ms 2800 KB Output is correct
93 Correct 3 ms 2292 KB Output is correct
94 Correct 4 ms 2288 KB Output is correct
95 Correct 3 ms 2284 KB Output is correct
96 Correct 3 ms 2552 KB Output is correct
97 Correct 1 ms 2028 KB Output is correct