답안 #946290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946290 2024-03-14T13:24:03 Z Pikachu 커다란 상품 (IOI17_prize) C++17
20 / 100
45 ms 3624 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;

pair<int,int> myask(int x)
{
    if (done) return make_pair(-1, -1);
    if (dak[x].first != -1) return dak[x];
    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 = 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:53: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]
   53 |     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 1 ms 1880 KB Output is correct
6 Correct 1 ms 1880 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 1880 KB Output is correct
4 Correct 1 ms 1880 KB Output is correct
5 Correct 1 ms 1880 KB Output is correct
6 Correct 1 ms 1880 KB Output is correct
7 Correct 1 ms 2132 KB Output is correct
8 Correct 1 ms 1880 KB Output is correct
9 Correct 1 ms 2132 KB Output is correct
10 Correct 1 ms 1880 KB Output is correct
11 Correct 2 ms 2284 KB Output is correct
12 Correct 1 ms 1996 KB Output is correct
13 Correct 3 ms 2300 KB Output is correct
14 Correct 1 ms 2032 KB Output is correct
15 Correct 4 ms 2312 KB Output is correct
16 Correct 23 ms 3100 KB Output is correct
17 Correct 1 ms 1880 KB Output is correct
18 Correct 24 ms 3356 KB Output is correct
19 Correct 1 ms 1880 KB Output is correct
20 Correct 5 ms 2328 KB Output is correct
21 Correct 8 ms 3088 KB Output is correct
22 Correct 3 ms 2032 KB Output is correct
23 Correct 1 ms 1880 KB Output is correct
24 Correct 1 ms 1880 KB Output is correct
25 Correct 12 ms 2828 KB Output is correct
26 Correct 10 ms 2864 KB Output is correct
27 Correct 1 ms 2032 KB Output is correct
28 Correct 23 ms 2896 KB Output is correct
29 Correct 13 ms 2696 KB Output is correct
30 Correct 24 ms 3480 KB Output is correct
31 Correct 1 ms 1880 KB Output is correct
32 Correct 2 ms 2296 KB Output is correct
33 Correct 1 ms 1880 KB Output is correct
34 Correct 9 ms 2320 KB Output is correct
35 Correct 1 ms 2028 KB Output is correct
36 Correct 6 ms 2304 KB Output is correct
37 Correct 2 ms 2028 KB Output is correct
38 Correct 1 ms 1880 KB Output is correct
39 Correct 11 ms 3104 KB Output is correct
40 Correct 22 ms 2680 KB Output is correct
41 Correct 15 ms 3380 KB Output is correct
42 Correct 15 ms 2804 KB Output is correct
43 Correct 14 ms 2744 KB Output is correct
44 Correct 10 ms 2096 KB Output is correct
45 Correct 7 ms 3060 KB Output is correct
46 Correct 1 ms 1880 KB Output is correct
47 Correct 10 ms 2288 KB Output is correct
48 Correct 14 ms 2876 KB Output is correct
49 Correct 2 ms 2044 KB Output is correct
50 Correct 21 ms 2704 KB Output is correct
51 Correct 9 ms 2600 KB Output is correct
52 Correct 1 ms 2028 KB Output is correct
53 Correct 1 ms 2028 KB Output is correct
54 Correct 11 ms 3056 KB Output is correct
55 Correct 1 ms 1880 KB Output is correct
56 Correct 23 ms 3556 KB Output is correct
57 Correct 17 ms 2644 KB Output is correct
58 Correct 18 ms 3100 KB Output is correct
59 Correct 13 ms 3172 KB Output is correct
60 Correct 12 ms 3144 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 2028 KB Output is correct
64 Correct 1 ms 2028 KB Output is correct
65 Correct 1 ms 2032 KB Output is correct
66 Correct 5 ms 2804 KB Output is correct
67 Correct 1 ms 1880 KB Output is correct
68 Correct 3 ms 2400 KB Output is correct
69 Correct 3 ms 2296 KB Output is correct
70 Correct 1 ms 2168 KB Output is correct
71 Correct 22 ms 2784 KB Output is correct
72 Correct 3 ms 2300 KB Output is correct
73 Correct 26 ms 3036 KB Output is correct
74 Correct 27 ms 2856 KB Output is correct
75 Correct 1 ms 2028 KB Output is correct
76 Correct 19 ms 3020 KB Output is correct
77 Correct 29 ms 3308 KB Output is correct
78 Correct 3 ms 2028 KB Output is correct
79 Correct 10 ms 2544 KB Output is correct
80 Correct 25 ms 3356 KB Output is correct
81 Correct 23 ms 3624 KB Output is correct
82 Correct 23 ms 2796 KB Output is correct
83 Correct 1 ms 2024 KB Output is correct
84 Correct 20 ms 3072 KB Output is correct
85 Correct 32 ms 2792 KB Output is correct
86 Incorrect 45 ms 3236 KB Incorrect
87 Halted 0 ms 0 KB -