Submission #957398

# Submission time Handle Problem Language Result Execution time Memory
957398 2024-04-03T16:08:27 Z kilkuwu The Big Prize (IOI17_prize) C++17
100 / 100
35 ms 16236 KB
#include "prize.h"
#include <bits/stdc++.h>

int find_best(int n) {
  std::vector<std::vector<int>> dp(n);

  auto query = [&](int i) -> std::vector<int> {
    if (dp[i].size()) return dp[i];
    return dp[i] = ask(i);
  };

  if (n <= 5000) {
    for (int i = 0; i < n; i++) {
      auto res = query(i);
      if (res[0] + res[1] == 0) {
        return i;
      }
    }
    return 0;
  }

  int answer = -1;

  std::vector<std::set<int>> mp(n);

  auto go = [&](auto self, int l, int r) -> void {
    if (l > r) return;
    if (answer >= 0) return;

    int m = (l + r) / 2;
    auto res = query(m);
    auto rnk = res[0] + res[1];

    if (res[0] + res[1] == 0) {
      answer = m;
      return;
    }

    auto it = mp[rnk].insert(m).first;

    if (it == mp[rnk].begin()) {
      if (res[0]) self(self, l, m - 1);
    } else {
      auto r1 = query(*std::prev(it));
      if (res[0] - r1[0] > 0) {
        self(self, l, m - 1);
      }
    }

    if (answer >= 0) return;

    it = mp[rnk].find(m);

    if (it == --mp[rnk].end()) {
      if (res[1]) self(self, m + 1, r);
    } else {
      auto r2 = query(*std::next(it));
      if (r2[0] - res[0] > 0) {
        self(self, m + 1, r);
      }
    }
  };

  go(go, 0, n - 1);

  return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14680 KB Output is correct
2 Correct 4 ms 14716 KB Output is correct
3 Correct 4 ms 14692 KB Output is correct
4 Correct 4 ms 14536 KB Output is correct
5 Correct 4 ms 14536 KB Output is correct
6 Correct 5 ms 14424 KB Output is correct
7 Correct 4 ms 14540 KB Output is correct
8 Correct 4 ms 14792 KB Output is correct
9 Correct 5 ms 14424 KB Output is correct
10 Correct 4 ms 14540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14656 KB Output is correct
2 Correct 4 ms 14536 KB Output is correct
3 Correct 4 ms 14536 KB Output is correct
4 Correct 5 ms 14680 KB Output is correct
5 Correct 4 ms 14536 KB Output is correct
6 Correct 4 ms 14540 KB Output is correct
7 Correct 4 ms 14540 KB Output is correct
8 Correct 4 ms 14536 KB Output is correct
9 Correct 4 ms 14424 KB Output is correct
10 Correct 4 ms 14424 KB Output is correct
11 Correct 6 ms 14536 KB Output is correct
12 Correct 4 ms 14540 KB Output is correct
13 Correct 7 ms 15056 KB Output is correct
14 Correct 2 ms 1936 KB Output is correct
15 Correct 8 ms 15072 KB Output is correct
16 Correct 25 ms 16004 KB Output is correct
17 Correct 4 ms 14424 KB Output is correct
18 Correct 26 ms 16092 KB Output is correct
19 Correct 5 ms 14536 KB Output is correct
20 Correct 8 ms 8068 KB Output is correct
21 Correct 15 ms 15844 KB Output is correct
22 Correct 7 ms 14796 KB Output is correct
23 Correct 4 ms 14536 KB Output is correct
24 Correct 5 ms 14424 KB Output is correct
25 Correct 18 ms 15176 KB Output is correct
26 Correct 14 ms 15676 KB Output is correct
27 Correct 5 ms 14540 KB Output is correct
28 Correct 30 ms 14860 KB Output is correct
29 Correct 21 ms 15708 KB Output is correct
30 Correct 25 ms 15688 KB Output is correct
31 Correct 5 ms 14540 KB Output is correct
32 Correct 6 ms 14556 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 15 ms 14816 KB Output is correct
35 Correct 5 ms 14544 KB Output is correct
36 Correct 10 ms 15200 KB Output is correct
37 Correct 5 ms 14548 KB Output is correct
38 Correct 4 ms 14544 KB Output is correct
39 Correct 16 ms 15596 KB Output is correct
40 Correct 26 ms 16236 KB Output is correct
41 Correct 16 ms 15628 KB Output is correct
42 Correct 18 ms 15384 KB Output is correct
43 Correct 18 ms 15280 KB Output is correct
44 Correct 15 ms 15628 KB Output is correct
45 Correct 10 ms 15376 KB Output is correct
46 Correct 5 ms 14536 KB Output is correct
47 Correct 14 ms 15356 KB Output is correct
48 Correct 21 ms 15324 KB Output is correct
49 Correct 6 ms 14816 KB Output is correct
50 Correct 28 ms 15808 KB Output is correct
51 Correct 14 ms 15352 KB Output is correct
52 Correct 4 ms 14544 KB Output is correct
53 Correct 6 ms 14976 KB Output is correct
54 Correct 12 ms 15396 KB Output is correct
55 Correct 5 ms 14540 KB Output is correct
56 Correct 27 ms 15916 KB Output is correct
57 Correct 21 ms 15996 KB Output is correct
58 Correct 23 ms 15384 KB Output is correct
59 Correct 17 ms 14916 KB Output is correct
60 Correct 18 ms 15392 KB Output is correct
61 Correct 5 ms 14540 KB Output is correct
62 Correct 5 ms 14716 KB Output is correct
63 Correct 5 ms 14940 KB Output is correct
64 Correct 5 ms 14548 KB Output is correct
65 Correct 6 ms 14540 KB Output is correct
66 Correct 5 ms 14424 KB Output is correct
67 Correct 4 ms 14536 KB Output is correct
68 Correct 4 ms 14424 KB Output is correct
69 Correct 4 ms 14540 KB Output is correct
70 Correct 5 ms 14712 KB Output is correct
71 Correct 31 ms 15500 KB Output is correct
72 Correct 6 ms 14828 KB Output is correct
73 Correct 27 ms 15424 KB Output is correct
74 Correct 25 ms 15620 KB Output is correct
75 Correct 5 ms 14788 KB Output is correct
76 Correct 35 ms 15336 KB Output is correct
77 Correct 34 ms 15688 KB Output is correct
78 Correct 6 ms 14800 KB Output is correct
79 Correct 18 ms 15848 KB Output is correct
80 Correct 32 ms 14692 KB Output is correct
81 Correct 34 ms 15592 KB Output is correct
82 Correct 25 ms 15352 KB Output is correct
83 Correct 4 ms 14536 KB Output is correct
84 Correct 29 ms 15504 KB Output is correct
85 Correct 30 ms 15756 KB Output is correct
86 Correct 7 ms 14536 KB Output is correct
87 Correct 5 ms 14528 KB Output is correct
88 Correct 7 ms 14796 KB Output is correct
89 Correct 6 ms 14796 KB Output is correct
90 Correct 4 ms 14540 KB Output is correct
91 Correct 5 ms 14536 KB Output is correct
92 Correct 4 ms 14680 KB Output is correct
93 Correct 6 ms 14564 KB Output is correct
94 Correct 7 ms 15056 KB Output is correct
95 Correct 5 ms 14704 KB Output is correct
96 Correct 5 ms 14556 KB Output is correct
97 Correct 4 ms 14540 KB Output is correct