답안 #778653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
778653 2023-07-10T14:17:30 Z benjaminkleyn 커다란 상품 (IOI17_prize) C++17
100 / 100
666 ms 2468 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;

bool asked[200000] = {false};
int L[200000], R[200000];

map<int, set<int>> queries;

bool Ask(int i)
{
    if (asked[i]) return L[i] + R[i] == 0;
    
    asked[i] = true;
    vector<int> res = ask(i);
    L[i] = res[0], R[i] = res[1];

    if (queries.find(L[i] + R[i]) == queries.end())
        queries[L[i] + R[i]] = set<int>();
    queries[L[i] + R[i]].insert(i);

    return L[i] + R[i] == 0;
}


int Find(int l, int r)
{
    if (Ask(l)) return l;
    if (Ask(r)) return r;
    if (l + 1 == r)
        return -1;

    for (auto [x, s] : queries)
    {
        auto it1 = s.upper_bound(l), it2 = s.lower_bound(r);
        if (it1 == s.begin() || it2 == s.end()) continue;
        if (L[*prev(it1)] == L[*it2]) return -1;
    }

    int m = (l + r) / 2;

    int x = Find(l, m);
    if (x >= 0) return x;

    int y = Find(m, r);
    if (y >= 0) return y;

    return -1;
}

int find_best(int n) 
{
    return Find(0, n - 1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 0 ms 316 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 3 ms 848 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 11 ms 1360 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 13 ms 608 KB Output is correct
16 Correct 367 ms 2052 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 509 ms 2428 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 32 ms 860 KB Output is correct
21 Correct 62 ms 1016 KB Output is correct
22 Correct 5 ms 528 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 116 ms 1424 KB Output is correct
26 Correct 128 ms 1440 KB Output is correct
27 Correct 1 ms 432 KB Output is correct
28 Correct 368 ms 2220 KB Output is correct
29 Correct 222 ms 2124 KB Output is correct
30 Correct 540 ms 2416 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 4 ms 1108 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 60 ms 988 KB Output is correct
35 Correct 3 ms 720 KB Output is correct
36 Correct 26 ms 808 KB Output is correct
37 Correct 2 ms 540 KB Output is correct
38 Correct 1 ms 312 KB Output is correct
39 Correct 96 ms 1232 KB Output is correct
40 Correct 394 ms 2344 KB Output is correct
41 Correct 165 ms 1564 KB Output is correct
42 Correct 175 ms 1496 KB Output is correct
43 Correct 135 ms 1408 KB Output is correct
44 Correct 71 ms 1132 KB Output is correct
45 Correct 43 ms 968 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 105 ms 1216 KB Output is correct
48 Correct 263 ms 1820 KB Output is correct
49 Correct 5 ms 432 KB Output is correct
50 Correct 530 ms 2428 KB Output is correct
51 Correct 82 ms 1096 KB Output is correct
52 Correct 1 ms 408 KB Output is correct
53 Correct 2 ms 692 KB Output is correct
54 Correct 87 ms 1180 KB Output is correct
55 Correct 1 ms 336 KB Output is correct
56 Correct 551 ms 2436 KB Output is correct
57 Correct 275 ms 1888 KB Output is correct
58 Correct 239 ms 1720 KB Output is correct
59 Correct 162 ms 1680 KB Output is correct
60 Correct 149 ms 1448 KB Output is correct
61 Correct 2 ms 720 KB Output is correct
62 Correct 1 ms 336 KB Output is correct
63 Correct 3 ms 684 KB Output is correct
64 Correct 1 ms 584 KB Output is correct
65 Correct 1 ms 464 KB Output is correct
66 Correct 1 ms 304 KB Output is correct
67 Correct 1 ms 336 KB Output is correct
68 Correct 1 ms 300 KB Output is correct
69 Correct 1 ms 336 KB Output is correct
70 Correct 1 ms 312 KB Output is correct
71 Correct 546 ms 2420 KB Output is correct
72 Correct 9 ms 1340 KB Output is correct
73 Correct 542 ms 2460 KB Output is correct
74 Correct 543 ms 2452 KB Output is correct
75 Correct 2 ms 720 KB Output is correct
76 Correct 393 ms 2412 KB Output is correct
77 Correct 575 ms 2460 KB Output is correct
78 Correct 11 ms 1376 KB Output is correct
79 Correct 139 ms 2268 KB Output is correct
80 Correct 558 ms 2468 KB Output is correct
81 Correct 543 ms 2424 KB Output is correct
82 Correct 563 ms 2384 KB Output is correct
83 Correct 3 ms 720 KB Output is correct
84 Correct 357 ms 2384 KB Output is correct
85 Correct 666 ms 2404 KB Output is correct
86 Correct 10 ms 1288 KB Output is correct
87 Correct 3 ms 960 KB Output is correct
88 Correct 7 ms 1204 KB Output is correct
89 Correct 8 ms 1104 KB Output is correct
90 Correct 3 ms 692 KB Output is correct
91 Correct 5 ms 848 KB Output is correct
92 Correct 1 ms 336 KB Output is correct
93 Correct 5 ms 972 KB Output is correct
94 Correct 6 ms 1104 KB Output is correct
95 Correct 6 ms 1084 KB Output is correct
96 Correct 5 ms 1020 KB Output is correct
97 Correct 1 ms 336 KB Output is correct