Submission #637622

# Submission time Handle Problem Language Result Execution time Memory
637622 2022-09-02T13:16:47 Z boris_mihov The Big Prize (IOI17_prize) C++17
90 / 100
73 ms 1872 KB
#include "prize.h"
#include <algorithm>
#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 200000 + 10;
const int INF  = 1e9;

int ans, n;
std::vector <int> res;
std::pair <int,int> asked[MAXN];
inline std::pair <int,int> query(int pos)
{
    assert(1 <= pos && pos <= n);
    if (asked[pos].first != -1) return asked[pos];
    res = ask(pos - 1);
    asked[pos] = {res[0], res[1]};
    if (res[0] == 0 && res[1] == 0) ans = pos;
    return asked[pos];
}

int leftCnt;
int rightCnt;
int cntBig;
int binaryCnt;

int binarySearchLeft(int from, int to)
{
    int l = from, r = to, mid;
    while (l < r - 1)
    {
        mid = (l + r) / 2;
        auto [left, right] = query(mid);
        if (ans != 0) return 0;
        if (left + right != cntBig)
        {
            r = mid;
            continue;
        }

        if (left != leftCnt)
        {
            r = mid;
            continue;
        }

        l = mid;
    }

    query(r);
    leftCnt++;
    return r;
}

int binarySearchRight(int from, int to)
{
    int l = from, r = to, mid;
    while (l < r - 1)
    {
        mid = (l + r) / 2;
        auto [left, right] = query(mid);
        if (ans != 0) return 0;
        if (left + right != cntBig)
        {
            l = mid;
            continue;
        }

        if (right != rightCnt)
        {
            l = mid;
            continue;
        }

        r = mid;
    }

    query(l);
    rightCnt++;
    return l;
}

int find_best(int N) 
{
    n = N;
	srand(6686889);
    std::fill(asked + 1, asked + 1 + n, std::make_pair(-1, -1));
    for (int i = 1 ; i <= std::min(n, 500) ; ++i)
    {
        query(i);
        cntBig = std::max(cntBig, asked[i].first + asked[i].second);
    }

    if (ans != 0) return ans - 1;
    for (int i = 1 ; i <= 500 ; ++i)    
    {
        leftCnt += (asked[i].first + asked[i].second != cntBig);
    }

    int l = 500, r = n + 1;
    while (ans == 0 && l < r - 1)
    {
        if (rand()%2 == 0) l = binarySearchLeft(l, r);
        else               r = binarySearchRight(l, r);
    }

    if (ans == 0 && l != 0) query(l);
    if (ans == 0 && r != n + 1) query(r);
    assert(asked[ans].first == 0 && asked[ans].second == 0);
    return ans - 1;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1744 KB Output is correct
2 Correct 4 ms 1744 KB Output is correct
3 Correct 3 ms 1744 KB Output is correct
4 Correct 4 ms 1744 KB Output is correct
5 Correct 4 ms 1744 KB Output is correct
6 Correct 4 ms 1836 KB Output is correct
7 Correct 3 ms 1832 KB Output is correct
8 Correct 3 ms 1832 KB Output is correct
9 Correct 4 ms 1744 KB Output is correct
10 Correct 5 ms 1744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1832 KB Output is correct
2 Correct 5 ms 1836 KB Output is correct
3 Correct 3 ms 1872 KB Output is correct
4 Correct 5 ms 1836 KB Output is correct
5 Correct 6 ms 1836 KB Output is correct
6 Correct 4 ms 1744 KB Output is correct
7 Correct 3 ms 1872 KB Output is correct
8 Correct 4 ms 1832 KB Output is correct
9 Correct 4 ms 1744 KB Output is correct
10 Correct 5 ms 1744 KB Output is correct
11 Correct 7 ms 1832 KB Output is correct
12 Correct 4 ms 1824 KB Output is correct
13 Correct 5 ms 1832 KB Output is correct
14 Correct 11 ms 464 KB Output is correct
15 Correct 23 ms 1836 KB Output is correct
16 Correct 13 ms 1816 KB Output is correct
17 Correct 5 ms 1836 KB Output is correct
18 Correct 7 ms 1744 KB Output is correct
19 Correct 5 ms 1744 KB Output is correct
20 Correct 30 ms 976 KB Output is correct
21 Partially correct 49 ms 1828 KB Partially correct - number of queries: 6257
22 Correct 18 ms 1736 KB Output is correct
23 Correct 3 ms 1836 KB Output is correct
24 Correct 3 ms 1816 KB Output is correct
25 Partially correct 68 ms 1828 KB Partially correct - number of queries: 7757
26 Partially correct 62 ms 1828 KB Partially correct - number of queries: 7875
27 Correct 7 ms 1836 KB Output is correct
28 Correct 12 ms 1832 KB Output is correct
29 Correct 19 ms 1840 KB Output is correct
30 Correct 5 ms 1744 KB Output is correct
31 Correct 6 ms 1828 KB Output is correct
32 Correct 5 ms 1836 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Partially correct 43 ms 1744 KB Partially correct - number of queries: 5343
35 Correct 8 ms 1744 KB Output is correct
36 Correct 42 ms 1840 KB Output is correct
37 Correct 7 ms 1816 KB Output is correct
38 Correct 4 ms 1744 KB Output is correct
39 Partially correct 54 ms 1744 KB Partially correct - number of queries: 7041
40 Correct 6 ms 1840 KB Output is correct
41 Partially correct 63 ms 1744 KB Partially correct - number of queries: 6475
42 Partially correct 43 ms 1832 KB Partially correct - number of queries: 6475
43 Partially correct 50 ms 1744 KB Partially correct - number of queries: 6995
44 Partially correct 54 ms 1840 KB Partially correct - number of queries: 6626
45 Partially correct 34 ms 1736 KB Partially correct - number of queries: 5458
46 Correct 4 ms 1744 KB Output is correct
47 Partially correct 73 ms 1832 KB Partially correct - number of queries: 7428
48 Partially correct 37 ms 1832 KB Partially correct - number of queries: 5087
49 Correct 16 ms 1744 KB Output is correct
50 Correct 5 ms 1836 KB Output is correct
51 Partially correct 54 ms 1840 KB Partially correct - number of queries: 6652
52 Correct 5 ms 1828 KB Output is correct
53 Correct 5 ms 1832 KB Output is correct
54 Partially correct 46 ms 1736 KB Partially correct - number of queries: 6865
55 Correct 6 ms 1832 KB Output is correct
56 Correct 5 ms 1832 KB Output is correct
57 Partially correct 53 ms 1744 KB Partially correct - number of queries: 5164
58 Partially correct 54 ms 1832 KB Partially correct - number of queries: 5105
59 Partially correct 59 ms 1812 KB Partially correct - number of queries: 6474
60 Partially correct 72 ms 1832 KB Partially correct - number of queries: 7314
61 Correct 6 ms 1744 KB Output is correct
62 Correct 6 ms 1832 KB Output is correct
63 Correct 6 ms 1836 KB Output is correct
64 Correct 7 ms 1744 KB Output is correct
65 Correct 4 ms 1744 KB Output is correct
66 Correct 5 ms 1836 KB Output is correct
67 Correct 3 ms 1828 KB Output is correct
68 Correct 6 ms 1840 KB Output is correct
69 Correct 7 ms 1744 KB Output is correct
70 Correct 3 ms 1824 KB Output is correct
71 Partially correct 72 ms 1744 KB Partially correct - number of queries: 8306
72 Correct 9 ms 1744 KB Output is correct
73 Partially correct 69 ms 1744 KB Partially correct - number of queries: 8177
74 Partially correct 52 ms 1744 KB Partially correct - number of queries: 8232
75 Correct 7 ms 1744 KB Output is correct
76 Partially correct 53 ms 1744 KB Partially correct - number of queries: 7115
77 Partially correct 65 ms 1744 KB Partially correct - number of queries: 8177
78 Correct 8 ms 1744 KB Output is correct
79 Correct 16 ms 1872 KB Output is correct
80 Partially correct 66 ms 1840 KB Partially correct - number of queries: 8170
81 Partially correct 61 ms 1744 KB Partially correct - number of queries: 8173
82 Partially correct 67 ms 1840 KB Partially correct - number of queries: 8083
83 Correct 5 ms 1744 KB Output is correct
84 Partially correct 51 ms 1744 KB Partially correct - number of queries: 6700
85 Partially correct 69 ms 1744 KB Partially correct - number of queries: 8154
86 Correct 6 ms 1744 KB Output is correct
87 Correct 5 ms 1744 KB Output is correct
88 Correct 5 ms 1744 KB Output is correct
89 Correct 6 ms 1744 KB Output is correct
90 Correct 5 ms 1744 KB Output is correct
91 Correct 6 ms 1744 KB Output is correct
92 Correct 4 ms 1744 KB Output is correct
93 Correct 10 ms 1744 KB Output is correct
94 Correct 9 ms 1744 KB Output is correct
95 Correct 8 ms 1744 KB Output is correct
96 Correct 9 ms 1744 KB Output is correct
97 Correct 5 ms 1744 KB Output is correct