Submission #784968

# Submission time Handle Problem Language Result Execution time Memory
784968 2023-07-16T20:41:43 Z Sam_a17 The Big Prize (IOI17_prize) C++17
90 / 100
77 ms 2792 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ld long double
#define ll long long

#define sz(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uniq(x) x.resize(unique(all(x)) - x.begin());
#define lb lower_bound
#define ub upper_bound

// for random generations
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 myrand(131);

std::vector<int> ask(int i);
const int N = 2e5 + 10;
pair<int, int> a[N];
int used[N];

int find_best(int n) {
  memset(used, -1, sizeof(used));

  int mxi = 0;
  for(int i = 0; i < 500; i++) {
    int cur = myrand() % n;
    while (used[cur] == 1) {
      cur = myrand() % n;
    }
    
    auto u = ask(cur);

    a[cur].first = u[0];
    a[cur].second = u[1];
    
    if((u[0] + u[1]) == 0) {
      return cur;
    }

    mxi = max(mxi, u[0] + u[1]);
    used[cur] = 1;
  }

  // if(n >= 150000) {
  //   assert(mxi >= 5000);
  // }

  for(int i = 0; i < n; i++) {
    int ina = i, inb = n - 1, answ = i;
    int lx, rx;
    if(used[i] != -1) {
      lx = a[i].first;
      rx = a[i].second;
    } else {
      auto u = ask(i);

      a[i].first = u[0];
      a[i].second = u[1];

      lx = u[0], rx = u[1];
      used[i] = 1;
    }

    if((lx + rx) == 0) {
      return i;
    }

    if((lx + rx) != mxi) {
      continue;
    }

    while(ina <= inb) {
      int mid = (ina + inb) / 2;
      int l = 0, r = 0;
      if(used[mid] != -1) {
        l = a[mid].first;
        r = a[mid].second;
      } else {
        auto u = ask(mid);

        a[mid].first = u[0];
        a[mid].second = u[1];

        l = u[0], r = u[1];
        used[i] = 1;
      }

      if((l + r) == 0) {
        return mid;
      }

      if(l == lx && (l + r) == (lx + rx)) {
        answ = mid;
        ina = mid + 1;
      } else {
        inb = mid - 1;
      }
    }

    i = answ;
  }

  // xd
  return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2096 KB Output is correct
2 Correct 3 ms 2120 KB Output is correct
3 Correct 6 ms 2216 KB Output is correct
4 Correct 3 ms 2112 KB Output is correct
5 Correct 5 ms 2236 KB Output is correct
6 Correct 6 ms 2084 KB Output is correct
7 Correct 3 ms 2276 KB Output is correct
8 Correct 5 ms 2096 KB Output is correct
9 Correct 3 ms 2120 KB Output is correct
10 Correct 5 ms 2256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2092 KB Output is correct
2 Correct 7 ms 2148 KB Output is correct
3 Correct 3 ms 2200 KB Output is correct
4 Correct 4 ms 2144 KB Output is correct
5 Correct 5 ms 2192 KB Output is correct
6 Correct 4 ms 2092 KB Output is correct
7 Correct 3 ms 2096 KB Output is correct
8 Correct 3 ms 2108 KB Output is correct
9 Correct 6 ms 2200 KB Output is correct
10 Correct 6 ms 2256 KB Output is correct
11 Correct 9 ms 2280 KB Output is correct
12 Correct 5 ms 2216 KB Output is correct
13 Correct 9 ms 2440 KB Output is correct
14 Correct 4 ms 1220 KB Output is correct
15 Correct 17 ms 2268 KB Output is correct
16 Partially correct 29 ms 2580 KB Partially correct - number of queries: 7818
17 Correct 4 ms 2256 KB Output is correct
18 Partially correct 53 ms 2612 KB Partially correct - number of queries: 9083
19 Correct 5 ms 2224 KB Output is correct
20 Correct 28 ms 1812 KB Output is correct
21 Correct 19 ms 2472 KB Output is correct
22 Correct 5 ms 2380 KB Output is correct
23 Correct 6 ms 2128 KB Output is correct
24 Correct 6 ms 2148 KB Output is correct
25 Partially correct 39 ms 2468 KB Partially correct - number of queries: 5354
26 Partially correct 30 ms 2564 KB Partially correct - number of queries: 5272
27 Correct 6 ms 2228 KB Output is correct
28 Partially correct 68 ms 2636 KB Partially correct - number of queries: 8665
29 Partially correct 54 ms 2504 KB Partially correct - number of queries: 6678
30 Partially correct 43 ms 2628 KB Partially correct - number of queries: 9019
31 Correct 5 ms 2096 KB Output is correct
32 Correct 10 ms 2348 KB Output is correct
33 Correct 1 ms 976 KB Output is correct
34 Correct 12 ms 2444 KB Output is correct
35 Correct 3 ms 2208 KB Output is correct
36 Correct 10 ms 2444 KB Output is correct
37 Correct 7 ms 2128 KB Output is correct
38 Correct 3 ms 2100 KB Output is correct
39 Correct 19 ms 2512 KB Output is correct
40 Partially correct 49 ms 2516 KB Partially correct - number of queries: 7765
41 Partially correct 20 ms 2556 KB Partially correct - number of queries: 5635
42 Partially correct 61 ms 2524 KB Partially correct - number of queries: 5632
43 Partially correct 47 ms 2424 KB Partially correct - number of queries: 5137
44 Correct 14 ms 2480 KB Output is correct
45 Correct 22 ms 2484 KB Output is correct
46 Correct 4 ms 2224 KB Output is correct
47 Correct 44 ms 2376 KB Output is correct
48 Partially correct 48 ms 2504 KB Partially correct - number of queries: 6846
49 Correct 7 ms 2308 KB Output is correct
50 Partially correct 56 ms 2608 KB Partially correct - number of queries: 9083
51 Correct 38 ms 2376 KB Output is correct
52 Correct 3 ms 2128 KB Output is correct
53 Correct 5 ms 2128 KB Output is correct
54 Correct 33 ms 2468 KB Output is correct
55 Correct 5 ms 2092 KB Output is correct
56 Partially correct 53 ms 2548 KB Partially correct - number of queries: 9081
57 Partially correct 58 ms 2512 KB Partially correct - number of queries: 6764
58 Partially correct 48 ms 2500 KB Partially correct - number of queries: 6868
59 Partially correct 47 ms 2472 KB Partially correct - number of queries: 5630
60 Partially correct 48 ms 2440 KB Partially correct - number of queries: 5249
61 Correct 7 ms 2256 KB Output is correct
62 Correct 5 ms 2128 KB Output is correct
63 Correct 6 ms 2224 KB Output is correct
64 Correct 5 ms 2164 KB Output is correct
65 Correct 6 ms 2128 KB Output is correct
66 Correct 4 ms 2176 KB Output is correct
67 Correct 4 ms 2216 KB Output is correct
68 Correct 5 ms 2108 KB Output is correct
69 Correct 10 ms 2076 KB Output is correct
70 Correct 6 ms 2120 KB Output is correct
71 Partially correct 50 ms 2792 KB Partially correct - number of queries: 9315
72 Correct 12 ms 2396 KB Output is correct
73 Partially correct 68 ms 2528 KB Partially correct - number of queries: 9177
74 Partially correct 68 ms 2576 KB Partially correct - number of queries: 9238
75 Correct 6 ms 2244 KB Output is correct
76 Partially correct 69 ms 2544 KB Partially correct - number of queries: 7964
77 Partially correct 77 ms 2628 KB Partially correct - number of queries: 9157
78 Correct 10 ms 2416 KB Output is correct
79 Correct 25 ms 2504 KB Output is correct
80 Partially correct 68 ms 2584 KB Partially correct - number of queries: 9187
81 Partially correct 32 ms 2628 KB Partially correct - number of queries: 9156
82 Partially correct 64 ms 2560 KB Partially correct - number of queries: 9101
83 Correct 6 ms 2256 KB Output is correct
84 Partially correct 32 ms 2596 KB Partially correct - number of queries: 7544
85 Partially correct 66 ms 2612 KB Partially correct - number of queries: 9184
86 Partially correct 28 ms 2484 KB Partially correct - number of queries: 6437
87 Correct 5 ms 2168 KB Output is correct
88 Partially correct 59 ms 2460 KB Partially correct - number of queries: 7094
89 Correct 42 ms 2532 KB Output is correct
90 Correct 7 ms 2236 KB Output is correct
91 Correct 20 ms 2452 KB Output is correct
92 Correct 33 ms 2500 KB Output is correct
93 Partially correct 43 ms 2592 KB Partially correct - number of queries: 7938
94 Partially correct 41 ms 2520 KB Partially correct - number of queries: 8161
95 Partially correct 72 ms 2704 KB Partially correct - number of queries: 8180
96 Partially correct 53 ms 2504 KB Partially correct - number of queries: 8105
97 Partially correct 53 ms 2504 KB Partially correct - number of queries: 7436