답안 #790513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
790513 2023-07-22T18:23:16 Z skittles1412 커다란 상품 (IOI17_prize) C++17
100 / 100
48 ms 1912 KB
#include "bits/extc++.h"

using namespace std;

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t;
    ((cerr << " | " << u), ...);
    cerr << endl;
}

#ifdef DEBUG
#define dbg(...)                                              \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
    dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr   \
    if (false) \
    cerr
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))

vector<int> ask(int i);

constexpr int maxn = 2e5 + 5;

struct Q {
    pair<int, int> cache[maxn];

    Q() {
        memset(cache, -1, sizeof(cache));
    }

    pair<int, int> query(int ind) {
        auto& ans = cache[ind];
        if (ans.first != -1) {
            return ans;
        }
        auto cv = ask(ind);
        assert(sz(cv) == 2);
        ans = {cv[0], cv[1]};
        return ans;
    }
} Q;

struct Solver {
    bool bad = false;
    int opt_ge, found_opt = -1, ans = -1;

    Solver(int n, int opt_ge) : opt_ge(opt_ge) {
        solve(0, n - 1, 0, 0);
    }

    void solve(int l, int r, int cl, int cr) {
        if (ans != -1 || bad || l > r || cl + cr == opt_ge) {
            return;
        }
        int small = 0;
        for (int mid = (l + r) / 2; mid <= r; mid++) {
            auto [ql, qr] = Q.query(mid);
            if (!ql && !qr) {
                ans = mid;
                return;
            }
            if (ql + qr < opt_ge) {
                small++;
                continue;
            }
            if (ql + qr > opt_ge) {
                bad = true;
                found_opt = max(found_opt, ql + qr);
                dbg("BAD");
                return;
            }
            dbg(mid);
            solve(mid + 1, r, ql, cr);
            solve(l, (l + r) / 2 - 1, cl, qr + small);
            return;
        }
        solve(l, (l + r) / 2 - 1, cl, cr + small);
    }
};

int find_best(int n) {
    int opt_ge = -1;
    while (true) {
        dbg(opt_ge);
        Solver s(n, opt_ge);
        if (s.ans != -1) {
            return s.ans;
        }
        assert(s.bad);
        opt_ge = s.found_opt;
    }
}

Compilation message

prize.cpp: In constructor 'Q::Q()':
prize.cpp:35:40: 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]
   35 |         memset(cache, -1, sizeof(cache));
      |                                        ^
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 /usr/include/x86_64-linux-gnu/c++/10/bits/extc++.h:32,
                 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 1856 KB Output is correct
2 Correct 1 ms 1856 KB Output is correct
3 Correct 1 ms 1844 KB Output is correct
4 Correct 1 ms 1860 KB Output is correct
5 Correct 1 ms 1860 KB Output is correct
6 Correct 1 ms 1872 KB Output is correct
7 Correct 1 ms 1860 KB Output is correct
8 Correct 1 ms 1856 KB Output is correct
9 Correct 1 ms 1744 KB Output is correct
10 Correct 1 ms 1744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1744 KB Output is correct
2 Correct 1 ms 1860 KB Output is correct
3 Correct 1 ms 1856 KB Output is correct
4 Correct 2 ms 1880 KB Output is correct
5 Correct 1 ms 1912 KB Output is correct
6 Correct 1 ms 1856 KB Output is correct
7 Correct 1 ms 1744 KB Output is correct
8 Correct 1 ms 1860 KB Output is correct
9 Correct 1 ms 1856 KB Output is correct
10 Correct 1 ms 1744 KB Output is correct
11 Correct 3 ms 1744 KB Output is correct
12 Correct 4 ms 1856 KB Output is correct
13 Correct 1 ms 1856 KB Output is correct
14 Correct 8 ms 1744 KB Output is correct
15 Correct 16 ms 1860 KB Output is correct
16 Correct 5 ms 1744 KB Output is correct
17 Correct 28 ms 1856 KB Output is correct
18 Correct 1 ms 1744 KB Output is correct
19 Correct 25 ms 1848 KB Output is correct
20 Correct 8 ms 1860 KB Output is correct
21 Correct 24 ms 1848 KB Output is correct
22 Correct 26 ms 1856 KB Output is correct
23 Correct 2 ms 1856 KB Output is correct
24 Correct 3 ms 1744 KB Output is correct
25 Correct 18 ms 1744 KB Output is correct
26 Correct 18 ms 1744 KB Output is correct
27 Correct 2 ms 1744 KB Output is correct
28 Correct 2 ms 1864 KB Output is correct
29 Correct 3 ms 1744 KB Output is correct
30 Correct 1 ms 1744 KB Output is correct
31 Correct 44 ms 1860 KB Output is correct
32 Correct 2 ms 1744 KB Output is correct
33 Correct 1 ms 1744 KB Output is correct
34 Correct 29 ms 1852 KB Output is correct
35 Correct 1 ms 1860 KB Output is correct
36 Correct 15 ms 1872 KB Output is correct
37 Correct 4 ms 1856 KB Output is correct
38 Correct 2 ms 1744 KB Output is correct
39 Correct 9 ms 1856 KB Output is correct
40 Correct 1 ms 1836 KB Output is correct
41 Correct 8 ms 1860 KB Output is correct
42 Correct 9 ms 1856 KB Output is correct
43 Correct 11 ms 1744 KB Output is correct
44 Correct 10 ms 1864 KB Output is correct
45 Correct 10 ms 1856 KB Output is correct
46 Correct 48 ms 1860 KB Output is correct
47 Correct 12 ms 1744 KB Output is correct
48 Correct 8 ms 1744 KB Output is correct
49 Correct 15 ms 1860 KB Output is correct
50 Correct 1 ms 1860 KB Output is correct
51 Correct 22 ms 1744 KB Output is correct
52 Correct 28 ms 1864 KB Output is correct
53 Correct 1 ms 1872 KB Output is correct
54 Correct 20 ms 1856 KB Output is correct
55 Correct 42 ms 1864 KB Output is correct
56 Correct 1 ms 1860 KB Output is correct
57 Correct 10 ms 1860 KB Output is correct
58 Correct 5 ms 1836 KB Output is correct
59 Correct 7 ms 1860 KB Output is correct
60 Correct 12 ms 1744 KB Output is correct
61 Correct 1 ms 1744 KB Output is correct
62 Correct 2 ms 1860 KB Output is correct
63 Correct 1 ms 1856 KB Output is correct
64 Correct 1 ms 1744 KB Output is correct
65 Correct 1 ms 1860 KB Output is correct
66 Correct 3 ms 1860 KB Output is correct
67 Correct 4 ms 1856 KB Output is correct
68 Correct 2 ms 1744 KB Output is correct
69 Correct 4 ms 1856 KB Output is correct
70 Correct 3 ms 1864 KB Output is correct
71 Correct 27 ms 1744 KB Output is correct
72 Correct 5 ms 1744 KB Output is correct
73 Correct 39 ms 1744 KB Output is correct
74 Correct 39 ms 1744 KB Output is correct
75 Correct 2 ms 1744 KB Output is correct
76 Correct 37 ms 1744 KB Output is correct
77 Correct 37 ms 1744 KB Output is correct
78 Correct 5 ms 1744 KB Output is correct
79 Correct 19 ms 1856 KB Output is correct
80 Correct 34 ms 1860 KB Output is correct
81 Correct 36 ms 1744 KB Output is correct
82 Correct 38 ms 1744 KB Output is correct
83 Correct 2 ms 1860 KB Output is correct
84 Correct 22 ms 1744 KB Output is correct
85 Correct 39 ms 1744 KB Output is correct
86 Correct 5 ms 1744 KB Output is correct
87 Correct 1 ms 1860 KB Output is correct
88 Correct 5 ms 1744 KB Output is correct
89 Correct 5 ms 1744 KB Output is correct
90 Correct 2 ms 1744 KB Output is correct
91 Correct 2 ms 1744 KB Output is correct
92 Correct 3 ms 1744 KB Output is correct
93 Correct 2 ms 1744 KB Output is correct
94 Correct 3 ms 1744 KB Output is correct
95 Correct 3 ms 1744 KB Output is correct
96 Correct 3 ms 1872 KB Output is correct
97 Correct 1 ms 1744 KB Output is correct