답안 #418023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
418023 2021-06-04T21:28:37 Z Hegdahl 커다란 상품 (IOI17_prize) C++17
100 / 100
59 ms 1780 KB
#include <bits/stdc++.h>
#include "prize.h"
#define ar array
using namespace std;

map<int, set<int>> where;
map<int, ar<int, 2>> mem;
map<int, map<int, int>> rightmost;
map<int, map<int, int>> leftmost;
ar<int, 2> qry(int i) {
  auto it = mem.find(i);
  if (it != mem.end()) return it->second;
  auto v = ask(i);
  int l = v[0], r = v[1];
  where[l+r].insert(i);

  if (!rightmost[l+r].count(l)) rightmost[l+r][l] = i;
  else rightmost[l+r][l] = max(rightmost[l+r][l], i);

  if (!leftmost[l+r].count(l)) leftmost[l+r][l] = i;
  else leftmost[l+r][l] = min(leftmost[l+r][l], i);

  return mem.insert({i, {l, r}}).first->second;
}

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int find_best(int n) {

  vector<int> idxs(n);
  iota(idxs.begin(), idxs.end(), 0);

  int need = sqrt(2e5)+1; // since adaptive it needs to be 100% probability of correct

  for (int rep = 0; rep < need; ++rep)
    qry(idxs[rep*n/need]);

  int worst = where.rbegin()->first;

  auto is_bad = [&](int i) {
    auto [l, r] = qry(i);
    return l+r == worst;
  };

  int i = 0;
  while (true) {
    while (i < n && !is_bad(i)) ++i;
    if (i == n) break;

    auto p = qry(i);
    auto [l, r] = p;

    auto rmit = rightmost[l+r].find(l);
    auto lmit = leftmost[l+r].upper_bound(l);

    int lo = rmit->second, hi;

    if (lmit == leftmost[l+r].end()) hi = n-1;
    else hi = lmit->second;

    while (lo != hi) {
      int ce = lo + (hi-lo+1)/2;
      if (qry(ce) == p) lo = ce;
      else hi = ce-1;
    }

    i = lo+1;
  }

  return *where[0].begin();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1096 KB Output is correct
2 Correct 6 ms 1096 KB Output is correct
3 Correct 4 ms 1164 KB Output is correct
4 Correct 3 ms 1096 KB Output is correct
5 Correct 5 ms 1044 KB Output is correct
6 Correct 4 ms 1096 KB Output is correct
7 Correct 3 ms 1116 KB Output is correct
8 Correct 5 ms 1120 KB Output is correct
9 Correct 6 ms 1096 KB Output is correct
10 Correct 5 ms 1096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1056 KB Output is correct
2 Correct 3 ms 1120 KB Output is correct
3 Correct 6 ms 1100 KB Output is correct
4 Correct 5 ms 1096 KB Output is correct
5 Correct 3 ms 1108 KB Output is correct
6 Correct 5 ms 1176 KB Output is correct
7 Correct 5 ms 1096 KB Output is correct
8 Correct 6 ms 1124 KB Output is correct
9 Correct 3 ms 1116 KB Output is correct
10 Correct 6 ms 1136 KB Output is correct
11 Correct 11 ms 1048 KB Output is correct
12 Correct 7 ms 1160 KB Output is correct
13 Correct 9 ms 1096 KB Output is correct
14 Correct 11 ms 444 KB Output is correct
15 Correct 27 ms 1664 KB Output is correct
16 Correct 45 ms 1600 KB Output is correct
17 Correct 28 ms 1608 KB Output is correct
18 Correct 54 ms 1600 KB Output is correct
19 Correct 49 ms 1560 KB Output is correct
20 Correct 27 ms 960 KB Output is correct
21 Correct 50 ms 1728 KB Output is correct
22 Correct 32 ms 1472 KB Output is correct
23 Correct 8 ms 1096 KB Output is correct
24 Correct 9 ms 1044 KB Output is correct
25 Correct 34 ms 1720 KB Output is correct
26 Correct 31 ms 1596 KB Output is correct
27 Correct 5 ms 1088 KB Output is correct
28 Correct 43 ms 1604 KB Output is correct
29 Correct 37 ms 1432 KB Output is correct
30 Correct 47 ms 1600 KB Output is correct
31 Correct 59 ms 1600 KB Output is correct
32 Correct 8 ms 1160 KB Output is correct
33 Correct 1 ms 200 KB Output is correct
34 Correct 48 ms 1600 KB Output is correct
35 Correct 6 ms 1044 KB Output is correct
36 Correct 29 ms 1612 KB Output is correct
37 Correct 9 ms 1056 KB Output is correct
38 Correct 6 ms 1096 KB Output is correct
39 Correct 42 ms 1612 KB Output is correct
40 Correct 44 ms 1472 KB Output is correct
41 Correct 51 ms 1564 KB Output is correct
42 Correct 28 ms 1660 KB Output is correct
43 Correct 37 ms 1680 KB Output is correct
44 Correct 46 ms 1576 KB Output is correct
45 Correct 41 ms 1492 KB Output is correct
46 Correct 36 ms 1648 KB Output is correct
47 Correct 30 ms 1780 KB Output is correct
48 Correct 28 ms 1668 KB Output is correct
49 Correct 44 ms 1600 KB Output is correct
50 Correct 51 ms 1624 KB Output is correct
51 Correct 49 ms 1632 KB Output is correct
52 Correct 47 ms 1648 KB Output is correct
53 Correct 6 ms 1120 KB Output is correct
54 Correct 51 ms 1564 KB Output is correct
55 Correct 53 ms 1628 KB Output is correct
56 Correct 43 ms 1560 KB Output is correct
57 Correct 56 ms 1600 KB Output is correct
58 Correct 34 ms 1776 KB Output is correct
59 Correct 51 ms 1588 KB Output is correct
60 Correct 46 ms 1608 KB Output is correct
61 Correct 6 ms 1128 KB Output is correct
62 Correct 5 ms 1044 KB Output is correct
63 Correct 4 ms 1144 KB Output is correct
64 Correct 7 ms 1088 KB Output is correct
65 Correct 5 ms 1120 KB Output is correct
66 Correct 10 ms 1160 KB Output is correct
67 Correct 10 ms 1112 KB Output is correct
68 Correct 6 ms 1144 KB Output is correct
69 Correct 9 ms 1096 KB Output is correct
70 Correct 9 ms 1136 KB Output is correct
71 Correct 49 ms 1512 KB Output is correct
72 Correct 6 ms 1124 KB Output is correct
73 Correct 38 ms 1568 KB Output is correct
74 Correct 43 ms 1560 KB Output is correct
75 Correct 6 ms 1096 KB Output is correct
76 Correct 41 ms 1452 KB Output is correct
77 Correct 29 ms 1656 KB Output is correct
78 Correct 8 ms 1096 KB Output is correct
79 Correct 24 ms 1344 KB Output is correct
80 Correct 55 ms 1648 KB Output is correct
81 Correct 53 ms 1644 KB Output is correct
82 Correct 48 ms 1604 KB Output is correct
83 Correct 5 ms 1096 KB Output is correct
84 Correct 43 ms 1532 KB Output is correct
85 Correct 46 ms 1568 KB Output is correct
86 Correct 47 ms 1560 KB Output is correct
87 Correct 8 ms 1168 KB Output is correct
88 Correct 42 ms 1524 KB Output is correct
89 Correct 39 ms 1596 KB Output is correct
90 Correct 6 ms 1052 KB Output is correct
91 Correct 31 ms 1300 KB Output is correct
92 Correct 37 ms 1600 KB Output is correct
93 Correct 51 ms 1608 KB Output is correct
94 Correct 43 ms 1600 KB Output is correct
95 Correct 41 ms 1744 KB Output is correct
96 Correct 51 ms 1644 KB Output is correct
97 Correct 45 ms 1596 KB Output is correct