Submission #98450

# Submission time Handle Problem Language Result Execution time Memory
98450 2019-02-23T17:34:28 Z bogdan10bos The Big Prize (IOI17_prize) C++14
100 / 100
56 ms 836 KB
#include <bits/stdc++.h>

#include "prize.h"

using namespace std;

typedef pair<int, int> pii;

int sq, mxcnt, ans;
map<int, int> mp[2];

pii myask(int pos)
{
    if(mp[0].count(pos))
        return {mp[0][pos], mp[1][pos]};

    auto v = ask(pos);
    mp[0][pos] = v[0];
    mp[1][pos] = v[1];
    return {v[0], v[1]};
}

void solve(int st, int dr)
{
    if(st > dr) return;
    if(ans != -1)   return;
    auto askst = myask(st);
    auto askdr = myask(dr);

    int sumst = askst.first + askst.second;
    int sumdr = askdr.first + askdr.second;

    if(sumst == 0)  { ans = st; return; }
    if(sumdr == 0)  { ans = dr; return; }

    if(askst.second == 0 || askdr.first == 0)   return;

    if(dr - st <= 1)    return;

    if(sumst != mxcnt)
    {
        solve(st + 1, dr);
        return;
    }

    if(sumdr != mxcnt)
    {
        solve(st, dr - 1);
        return;
    }

    int cnt = askdr.first - askst.first;
    if(cnt == 0)    return;

    int lgt = dr - st - 1;

    int mij = st + (dr - st) / 2;

    solve(st, mij);
    solve(mij, dr);
}

int find_best(int N)
{
    ans = -1;
    sq = sqrt(N) + 1;
    sq = min(sq, N);
    mxcnt = 0;

    mt19937 g(chrono::high_resolution_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> uid(0, N - 1);

    for(int i = 0; i - sq < N; i += sq)
    {
        int pos = min(i, N - 1);
        auto x = myask(pos);
        int sum = x.first + x.second;
        if(sum == 0)    ans = pos;
        mxcnt = max(mxcnt, sum);
    }

	for(int i = 0; i < 100; i++)
    {
        int pos = uid(g);
        auto x = myask(pos);
        int sum = x.first + x.second;
        if(sum == 0)    ans = pos;
        mxcnt = max(mxcnt, sum);
    }
    int st = 0, dr = sq;
    for(; st < N; )
    {
        solve(st, dr);
        st += sq; dr += sq;
        if(dr >= N) dr = N - 1;
    }
    return ans;
}

Compilation message

prize.cpp: In function 'void solve(int, int)':
prize.cpp:55:9: warning: unused variable 'lgt' [-Wunused-variable]
     int lgt = dr - st - 1;
         ^~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 7 ms 304 KB Output is correct
3 Correct 6 ms 368 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 8 ms 308 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 14 ms 340 KB Output is correct
9 Correct 11 ms 308 KB Output is correct
10 Correct 6 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 5 ms 452 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 10 ms 316 KB Output is correct
5 Correct 10 ms 256 KB Output is correct
6 Correct 8 ms 256 KB Output is correct
7 Correct 4 ms 432 KB Output is correct
8 Correct 5 ms 488 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 10 ms 384 KB Output is correct
11 Correct 5 ms 484 KB Output is correct
12 Correct 5 ms 452 KB Output is correct
13 Correct 11 ms 376 KB Output is correct
14 Correct 8 ms 256 KB Output is correct
15 Correct 9 ms 564 KB Output is correct
16 Correct 32 ms 632 KB Output is correct
17 Correct 8 ms 568 KB Output is correct
18 Correct 46 ms 692 KB Output is correct
19 Correct 5 ms 448 KB Output is correct
20 Correct 17 ms 504 KB Output is correct
21 Correct 16 ms 524 KB Output is correct
22 Correct 11 ms 376 KB Output is correct
23 Correct 8 ms 256 KB Output is correct
24 Correct 4 ms 572 KB Output is correct
25 Correct 27 ms 560 KB Output is correct
26 Correct 24 ms 536 KB Output is correct
27 Correct 10 ms 384 KB Output is correct
28 Correct 28 ms 732 KB Output is correct
29 Correct 31 ms 620 KB Output is correct
30 Correct 43 ms 632 KB Output is correct
31 Correct 7 ms 256 KB Output is correct
32 Correct 9 ms 312 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 23 ms 480 KB Output is correct
35 Correct 7 ms 436 KB Output is correct
36 Correct 19 ms 376 KB Output is correct
37 Correct 6 ms 436 KB Output is correct
38 Correct 8 ms 256 KB Output is correct
39 Correct 30 ms 376 KB Output is correct
40 Correct 29 ms 648 KB Output is correct
41 Correct 33 ms 648 KB Output is correct
42 Correct 30 ms 588 KB Output is correct
43 Correct 21 ms 556 KB Output is correct
44 Correct 29 ms 420 KB Output is correct
45 Correct 20 ms 428 KB Output is correct
46 Correct 5 ms 452 KB Output is correct
47 Correct 21 ms 504 KB Output is correct
48 Correct 41 ms 640 KB Output is correct
49 Correct 13 ms 388 KB Output is correct
50 Correct 47 ms 788 KB Output is correct
51 Correct 26 ms 504 KB Output is correct
52 Correct 8 ms 316 KB Output is correct
53 Correct 5 ms 372 KB Output is correct
54 Correct 24 ms 520 KB Output is correct
55 Correct 8 ms 256 KB Output is correct
56 Correct 47 ms 836 KB Output is correct
57 Correct 41 ms 636 KB Output is correct
58 Correct 20 ms 812 KB Output is correct
59 Correct 18 ms 756 KB Output is correct
60 Correct 25 ms 556 KB Output is correct
61 Correct 8 ms 304 KB Output is correct
62 Correct 5 ms 452 KB Output is correct
63 Correct 7 ms 256 KB Output is correct
64 Correct 9 ms 320 KB Output is correct
65 Correct 9 ms 304 KB Output is correct
66 Correct 9 ms 376 KB Output is correct
67 Correct 13 ms 376 KB Output is correct
68 Correct 14 ms 312 KB Output is correct
69 Correct 10 ms 376 KB Output is correct
70 Correct 8 ms 376 KB Output is correct
71 Correct 47 ms 660 KB Output is correct
72 Correct 12 ms 396 KB Output is correct
73 Correct 41 ms 760 KB Output is correct
74 Correct 42 ms 692 KB Output is correct
75 Correct 7 ms 504 KB Output is correct
76 Correct 41 ms 792 KB Output is correct
77 Correct 31 ms 688 KB Output is correct
78 Correct 11 ms 376 KB Output is correct
79 Correct 25 ms 504 KB Output is correct
80 Correct 45 ms 708 KB Output is correct
81 Correct 44 ms 648 KB Output is correct
82 Correct 40 ms 692 KB Output is correct
83 Correct 6 ms 512 KB Output is correct
84 Correct 28 ms 668 KB Output is correct
85 Correct 56 ms 784 KB Output is correct
86 Correct 9 ms 256 KB Output is correct
87 Correct 7 ms 396 KB Output is correct
88 Correct 9 ms 512 KB Output is correct
89 Correct 7 ms 256 KB Output is correct
90 Correct 8 ms 256 KB Output is correct
91 Correct 8 ms 256 KB Output is correct
92 Correct 7 ms 256 KB Output is correct
93 Correct 20 ms 424 KB Output is correct
94 Correct 19 ms 384 KB Output is correct
95 Correct 24 ms 376 KB Output is correct
96 Correct 14 ms 376 KB Output is correct
97 Correct 7 ms 256 KB Output is correct