답안 #316244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
316244 2020-10-25T17:58:14 Z MrDomino 커다란 상품 (IOI17_prize) C++14
100 / 100
58 ms 15620 KB
#include <bits/stdc++.h>
#include "prize.h"

using namespace std;

mt19937 rng((long long) (new char));
const int N = 200000 + 7;
vector<int> ret[N];
set<int> s[N];
set<int> sums;
int sol;
int pos;

vector<int> get(int i) {
  if (ret[i].empty()) {
    ret[i] = ask(i);
    if (ret[i][0] == 0 && ret[i][1] == 0) {
      sol = i;
    }
  }
  sums.insert(ret[i][0] + ret[i][1]);
  s[ret[i][0] + ret[i][1]].insert(i);
  return ret[i];
}

int rep(int l, int r) {
  if (l > r) {
    return 0;
  }
  for (auto &x : sums) {
    auto it = s[x].lower_bound(r);
    if (it != s[x].end()) {
      auto it2 = s[x].lower_bound(l + 1);
      if (it2 != s[x].begin()) {
        it2--;
        int f = *it2;
        int s = *it;
        if (get(f)[0] == get(s)[0]) {
          return 0;
        }
      }
    }
  }
  int m = (l + r) / 2;
  if (get(m)[0] == 0 && get(m)[1] == 0) {
    return m;
  }
  if (rng() & 1) {
    int x = rep(m + 1, r);
    if (x == 0) {
      x = rep(l, m - 1);
    }
    return x;
  } else {
    int x = rep(l, m - 1);
    if (x == 0) {
      x = rep(m + 1, r);
    }
    return x;
  }
}

int find_best(int n) {
  sol = -1;
  vector<int> ord(n);
  for (int i = 0; i < n; i++) {
    ord[i] = i;
  }
  shuffle(ord.begin(), ord.end(), rng);
  while ((int) ord.size() > 447) {
    ord.pop_back();
  }
  for (auto &x : ord) {
    get(x);
  }
  if (sol != -1) {
    return sol;
  }
  return rep(0, n - 1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 15232 KB Output is correct
2 Correct 22 ms 15232 KB Output is correct
3 Correct 20 ms 15428 KB Output is correct
4 Correct 19 ms 15292 KB Output is correct
5 Correct 23 ms 15228 KB Output is correct
6 Correct 21 ms 15224 KB Output is correct
7 Correct 22 ms 15264 KB Output is correct
8 Correct 21 ms 15180 KB Output is correct
9 Correct 21 ms 15232 KB Output is correct
10 Correct 20 ms 15232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 15232 KB Output is correct
2 Correct 20 ms 15232 KB Output is correct
3 Correct 21 ms 15224 KB Output is correct
4 Correct 24 ms 15224 KB Output is correct
5 Correct 20 ms 15272 KB Output is correct
6 Correct 21 ms 15224 KB Output is correct
7 Correct 22 ms 15232 KB Output is correct
8 Correct 24 ms 15224 KB Output is correct
9 Correct 20 ms 15296 KB Output is correct
10 Correct 20 ms 15232 KB Output is correct
11 Correct 20 ms 15312 KB Output is correct
12 Correct 22 ms 15224 KB Output is correct
13 Correct 22 ms 15224 KB Output is correct
14 Correct 18 ms 14504 KB Output is correct
15 Correct 27 ms 15224 KB Output is correct
16 Correct 32 ms 15352 KB Output is correct
17 Correct 36 ms 15352 KB Output is correct
18 Correct 45 ms 15404 KB Output is correct
19 Correct 27 ms 15272 KB Output is correct
20 Correct 26 ms 14968 KB Output is correct
21 Correct 24 ms 15360 KB Output is correct
22 Correct 39 ms 15256 KB Output is correct
23 Correct 21 ms 15308 KB Output is correct
24 Correct 23 ms 15356 KB Output is correct
25 Correct 35 ms 15428 KB Output is correct
26 Correct 45 ms 15364 KB Output is correct
27 Correct 23 ms 15220 KB Output is correct
28 Correct 34 ms 15352 KB Output is correct
29 Correct 28 ms 15352 KB Output is correct
30 Correct 35 ms 15256 KB Output is correct
31 Correct 25 ms 15356 KB Output is correct
32 Correct 28 ms 15232 KB Output is correct
33 Correct 11 ms 14472 KB Output is correct
34 Correct 38 ms 15312 KB Output is correct
35 Correct 22 ms 15444 KB Output is correct
36 Correct 39 ms 15388 KB Output is correct
37 Correct 23 ms 15224 KB Output is correct
38 Correct 21 ms 15224 KB Output is correct
39 Correct 28 ms 15352 KB Output is correct
40 Correct 34 ms 15352 KB Output is correct
41 Correct 26 ms 15232 KB Output is correct
42 Correct 25 ms 15232 KB Output is correct
43 Correct 30 ms 15352 KB Output is correct
44 Correct 24 ms 15372 KB Output is correct
45 Correct 24 ms 15224 KB Output is correct
46 Correct 23 ms 15356 KB Output is correct
47 Correct 23 ms 15352 KB Output is correct
48 Correct 31 ms 15352 KB Output is correct
49 Correct 30 ms 15352 KB Output is correct
50 Correct 39 ms 15480 KB Output is correct
51 Correct 35 ms 15352 KB Output is correct
52 Correct 31 ms 15352 KB Output is correct
53 Correct 21 ms 15424 KB Output is correct
54 Correct 25 ms 15224 KB Output is correct
55 Correct 44 ms 15352 KB Output is correct
56 Correct 22 ms 15224 KB Output is correct
57 Correct 21 ms 15440 KB Output is correct
58 Correct 33 ms 15352 KB Output is correct
59 Correct 31 ms 15352 KB Output is correct
60 Correct 32 ms 15352 KB Output is correct
61 Correct 19 ms 15280 KB Output is correct
62 Correct 20 ms 15232 KB Output is correct
63 Correct 22 ms 15224 KB Output is correct
64 Correct 24 ms 15232 KB Output is correct
65 Correct 20 ms 15224 KB Output is correct
66 Correct 22 ms 15224 KB Output is correct
67 Correct 21 ms 15224 KB Output is correct
68 Correct 20 ms 15232 KB Output is correct
69 Correct 22 ms 15232 KB Output is correct
70 Correct 21 ms 15232 KB Output is correct
71 Correct 53 ms 15480 KB Output is correct
72 Correct 28 ms 15232 KB Output is correct
73 Correct 57 ms 15620 KB Output is correct
74 Correct 58 ms 15480 KB Output is correct
75 Correct 22 ms 15232 KB Output is correct
76 Correct 49 ms 15352 KB Output is correct
77 Correct 58 ms 15356 KB Output is correct
78 Correct 22 ms 15232 KB Output is correct
79 Correct 35 ms 15352 KB Output is correct
80 Correct 52 ms 15352 KB Output is correct
81 Correct 54 ms 15352 KB Output is correct
82 Correct 46 ms 15480 KB Output is correct
83 Correct 21 ms 15232 KB Output is correct
84 Correct 43 ms 15352 KB Output is correct
85 Correct 43 ms 15552 KB Output is correct
86 Correct 24 ms 15232 KB Output is correct
87 Correct 24 ms 15360 KB Output is correct
88 Correct 24 ms 15232 KB Output is correct
89 Correct 24 ms 15232 KB Output is correct
90 Correct 21 ms 15232 KB Output is correct
91 Correct 22 ms 15232 KB Output is correct
92 Correct 23 ms 15232 KB Output is correct
93 Correct 27 ms 15360 KB Output is correct
94 Correct 23 ms 15296 KB Output is correct
95 Correct 31 ms 15232 KB Output is correct
96 Correct 26 ms 15232 KB Output is correct
97 Correct 22 ms 15232 KB Output is correct