답안 #946297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946297 2024-03-14T13:28:20 Z Pikachu 커다란 상품 (IOI17_prize) C++17
20 / 100
45 ms 3684 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] >= 500) assert(false);
    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 = 10;
    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:57: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]
   57 |     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
      |            ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1880 KB Output is correct
3 Correct 1 ms 1880 KB Output is correct
4 Correct 1 ms 1880 KB Output is correct
5 Correct 2 ms 1880 KB Output is correct
6 Correct 1 ms 2132 KB Output is correct
7 Correct 1 ms 1880 KB Output is correct
8 Correct 1 ms 1880 KB Output is correct
9 Correct 1 ms 1880 KB Output is correct
10 Correct 1 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Output is correct
2 Correct 1 ms 1880 KB Output is correct
3 Correct 1 ms 1996 KB Output is correct
4 Correct 1 ms 1880 KB Output is correct
5 Correct 2 ms 1880 KB Output is correct
6 Correct 1 ms 1880 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1880 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1880 KB Output is correct
11 Correct 2 ms 2032 KB Output is correct
12 Correct 1 ms 1880 KB Output is correct
13 Correct 3 ms 2284 KB Output is correct
14 Correct 1 ms 2028 KB Output is correct
15 Correct 4 ms 2568 KB Output is correct
16 Correct 24 ms 2872 KB Output is correct
17 Correct 1 ms 1880 KB Output is correct
18 Correct 32 ms 3148 KB Output is correct
19 Correct 1 ms 1880 KB Output is correct
20 Correct 7 ms 2820 KB Output is correct
21 Correct 11 ms 2300 KB Output is correct
22 Correct 2 ms 2040 KB Output is correct
23 Correct 1 ms 1880 KB Output is correct
24 Correct 1 ms 1880 KB Output is correct
25 Correct 13 ms 2872 KB Output is correct
26 Correct 11 ms 2880 KB Output is correct
27 Correct 1 ms 2032 KB Output is correct
28 Correct 23 ms 3184 KB Output is correct
29 Correct 15 ms 2560 KB Output is correct
30 Correct 20 ms 3064 KB Output is correct
31 Correct 1 ms 1880 KB Output is correct
32 Correct 4 ms 2288 KB Output is correct
33 Correct 1 ms 1880 KB Output is correct
34 Correct 7 ms 2088 KB Output is correct
35 Correct 2 ms 2028 KB Output is correct
36 Correct 6 ms 2804 KB Output is correct
37 Correct 1 ms 2032 KB Output is correct
38 Correct 1 ms 1880 KB Output is correct
39 Correct 11 ms 2572 KB Output is correct
40 Correct 22 ms 2964 KB Output is correct
41 Correct 17 ms 2564 KB Output is correct
42 Correct 15 ms 2608 KB Output is correct
43 Correct 20 ms 2288 KB Output is correct
44 Correct 10 ms 2600 KB Output is correct
45 Correct 8 ms 2548 KB Output is correct
46 Correct 1 ms 1880 KB Output is correct
47 Correct 11 ms 2720 KB Output is correct
48 Correct 14 ms 2700 KB Output is correct
49 Correct 2 ms 2044 KB Output is correct
50 Correct 23 ms 2864 KB Output is correct
51 Correct 12 ms 3360 KB Output is correct
52 Correct 1 ms 2020 KB Output is correct
53 Correct 1 ms 2028 KB Output is correct
54 Correct 11 ms 2608 KB Output is correct
55 Correct 1 ms 1880 KB Output is correct
56 Correct 31 ms 3328 KB Output is correct
57 Correct 20 ms 2568 KB Output is correct
58 Correct 16 ms 3084 KB Output is correct
59 Correct 14 ms 2568 KB Output is correct
60 Correct 12 ms 3356 KB Output is correct
61 Correct 1 ms 2032 KB Output is correct
62 Correct 1 ms 1880 KB Output is correct
63 Correct 1 ms 2036 KB Output is correct
64 Correct 1 ms 2028 KB Output is correct
65 Correct 1 ms 2028 KB Output is correct
66 Correct 3 ms 2548 KB Output is correct
67 Correct 2 ms 2292 KB Output is correct
68 Correct 2 ms 2296 KB Output is correct
69 Correct 3 ms 2288 KB Output is correct
70 Correct 1 ms 2028 KB Output is correct
71 Correct 24 ms 2752 KB Output is correct
72 Correct 3 ms 2052 KB Output is correct
73 Correct 22 ms 2648 KB Output is correct
74 Correct 26 ms 2720 KB Output is correct
75 Correct 1 ms 2028 KB Output is correct
76 Correct 28 ms 2504 KB Output is correct
77 Correct 26 ms 3460 KB Output is correct
78 Correct 3 ms 2284 KB Output is correct
79 Correct 11 ms 2804 KB Output is correct
80 Correct 24 ms 3444 KB Output is correct
81 Correct 31 ms 3448 KB Output is correct
82 Correct 25 ms 3420 KB Output is correct
83 Correct 2 ms 2032 KB Output is correct
84 Correct 29 ms 2572 KB Output is correct
85 Correct 23 ms 3308 KB Output is correct
86 Incorrect 45 ms 3684 KB Incorrect
87 Halted 0 ms 0 KB -