Submission #946298

# Submission time Handle Problem Language Result Execution time Memory
946298 2024-03-14T13:29:05 Z Pikachu The Big Prize (IOI17_prize) C++17
20 / 100
61 ms 3420 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;
    }
    while (!done) {
        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 2 ms 2032 KB Output is correct
2 Correct 1 ms 2032 KB Output is correct
3 Correct 1 ms 2036 KB Output is correct
4 Correct 1 ms 2032 KB Output is correct
5 Correct 2 ms 2028 KB Output is correct
6 Correct 2 ms 2172 KB Output is correct
7 Correct 1 ms 2028 KB Output is correct
8 Correct 1 ms 2032 KB Output is correct
9 Correct 1 ms 2028 KB Output is correct
10 Correct 2 ms 2024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2028 KB Output is correct
2 Correct 1 ms 2032 KB Output is correct
3 Correct 1 ms 2036 KB Output is correct
4 Correct 1 ms 2028 KB Output is correct
5 Correct 1 ms 2028 KB Output is correct
6 Correct 1 ms 2032 KB Output is correct
7 Correct 2 ms 2036 KB Output is correct
8 Correct 1 ms 2032 KB Output is correct
9 Correct 1 ms 2036 KB Output is correct
10 Correct 1 ms 2024 KB Output is correct
11 Correct 2 ms 2032 KB Output is correct
12 Correct 1 ms 2028 KB Output is correct
13 Correct 3 ms 2288 KB Output is correct
14 Correct 2 ms 2024 KB Output is correct
15 Correct 4 ms 2308 KB Output is correct
16 Correct 18 ms 3132 KB Output is correct
17 Correct 2 ms 2036 KB Output is correct
18 Correct 30 ms 2820 KB Output is correct
19 Correct 1 ms 2024 KB Output is correct
20 Correct 8 ms 2320 KB Output is correct
21 Correct 10 ms 2876 KB Output is correct
22 Correct 3 ms 2292 KB Output is correct
23 Correct 1 ms 2032 KB Output is correct
24 Correct 1 ms 2028 KB Output is correct
25 Correct 13 ms 3372 KB Output is correct
26 Correct 12 ms 2572 KB Output is correct
27 Correct 1 ms 2028 KB Output is correct
28 Correct 18 ms 3224 KB Output is correct
29 Correct 13 ms 3420 KB Output is correct
30 Correct 30 ms 2632 KB Output is correct
31 Correct 1 ms 2028 KB Output is correct
32 Correct 3 ms 2296 KB Output is correct
33 Correct 1 ms 2024 KB Output is correct
34 Correct 8 ms 2576 KB Output is correct
35 Correct 2 ms 2032 KB Output is correct
36 Correct 6 ms 2564 KB Output is correct
37 Correct 2 ms 2036 KB Output is correct
38 Correct 1 ms 2028 KB Output is correct
39 Correct 15 ms 2900 KB Output is correct
40 Correct 18 ms 2928 KB Output is correct
41 Correct 18 ms 2348 KB Output is correct
42 Correct 17 ms 2672 KB Output is correct
43 Correct 11 ms 2600 KB Output is correct
44 Correct 9 ms 2864 KB Output is correct
45 Correct 7 ms 3108 KB Output is correct
46 Correct 1 ms 2032 KB Output is correct
47 Correct 9 ms 2604 KB Output is correct
48 Correct 15 ms 2468 KB Output is correct
49 Correct 3 ms 2548 KB Output is correct
50 Correct 26 ms 3384 KB Output is correct
51 Correct 10 ms 2376 KB Output is correct
52 Correct 2 ms 2036 KB Output is correct
53 Correct 2 ms 2032 KB Output is correct
54 Correct 11 ms 2872 KB Output is correct
55 Correct 2 ms 2024 KB Output is correct
56 Correct 23 ms 2352 KB Output is correct
57 Correct 23 ms 3368 KB Output is correct
58 Correct 18 ms 2604 KB Output is correct
59 Correct 13 ms 2860 KB Output is correct
60 Correct 11 ms 3376 KB Output is correct
61 Correct 2 ms 2032 KB Output is correct
62 Correct 1 ms 2032 KB Output is correct
63 Correct 5 ms 2032 KB Output is correct
64 Correct 2 ms 2028 KB Output is correct
65 Correct 1 ms 2036 KB Output is correct
66 Correct 3 ms 2300 KB Output is correct
67 Correct 2 ms 2036 KB Output is correct
68 Correct 4 ms 1880 KB Output is correct
69 Correct 3 ms 2312 KB Output is correct
70 Correct 2 ms 2284 KB Output is correct
71 Correct 30 ms 2916 KB Output is correct
72 Correct 3 ms 2548 KB Output is correct
73 Correct 25 ms 3164 KB Output is correct
74 Correct 23 ms 3016 KB Output is correct
75 Correct 2 ms 2288 KB Output is correct
76 Correct 23 ms 2648 KB Output is correct
77 Correct 33 ms 3248 KB Output is correct
78 Correct 3 ms 2536 KB Output is correct
79 Correct 12 ms 2544 KB Output is correct
80 Correct 25 ms 3076 KB Output is correct
81 Correct 23 ms 3128 KB Output is correct
82 Correct 22 ms 2896 KB Output is correct
83 Correct 2 ms 2024 KB Output is correct
84 Correct 24 ms 2912 KB Output is correct
85 Correct 35 ms 2708 KB Output is correct
86 Incorrect 61 ms 3352 KB Incorrect
87 Halted 0 ms 0 KB -