Submission #292739

# Submission time Handle Problem Language Result Execution time Memory
292739 2020-09-07T12:41:25 Z Kastanda The Big Prize (IOI17_prize) C++11
97.62 / 100
60 ms 5252 KB
// M
#include<bits/stdc++.h>
#include "prize.h"
using namespace std;
const int N = 200005;
int n, GRes, MX;
vector < int > A[N];
inline void Ask(int i)
{
        if (!A[i].size())
                A[i] = ask(i);
}
void Solve(int l, int r, int k, int le = 0, int ri = 0)
{
        //printf("%d :: %d :: %d\n", l, r, k);
        if (r <= l || k == 0)
                return ;
        if (GRes != -1)
                return ;
        if (r - l == 1)
        {
                Ask(l);
                if (A[l][0] + A[l][1] == 0)
                        GRes = l;
                return ;
        }
        int md1 = (l + r) >> 1;
        int md2 = md1;
        int cc = 0;
        int ww = 0;
        while (md2 < r && md1 >= l)
        {
                Ask(md2);
                if (A[md2][0] + A[md2][1] == 0)
                {
                        GRes = md2;
                        return ;
                }
                if (A[md2][0] + A[md2][1] == MX)
                        break;
                cc ++;
                assert(cc <= k);
                md2 ++;
        }
        if (md2 == r)
        {
                Solve(l, md1, k - cc, le, ri + cc);
                return ;
        }
        Solve(l, md1, k - cc - (A[md2][1] - ri), le, cc + A[md2][1]);
        Solve(md2 + 1, r, A[md2][1] - ri, A[md2][0], ri);
}

int find_best(int _n)
{
        n = _n;

        if (n <= 5000)
        {
                for (int i = 0; i < n; i ++)
                {
                        vector < int > TMp = ask(i);
                        if (TMp[0] + TMp[1] == 0)
                                return i;
                }
        }
        int SQ = 479;
        MX = 0;
        int opt = -1;
        for (int i = 0; i < SQ; i ++)
        {
                Ask(i);
                if (A[i][0] + A[i][1] == 0)
                        return i;
                if (MX <= A[i][0] + A[i][1])
                        MX = A[i][0] + A[i][1], opt = i;
        }
        GRes = -1;
  assert(opt != -1);
        Solve(opt + 1, n, A[opt][1], A[opt][0], 0);
        return GRes;
}

Compilation message

prize.cpp: In function 'void Solve(int, int, int, int, int)':
prize.cpp:30:13: warning: unused variable 'ww' [-Wunused-variable]
   30 |         int ww = 0;
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4992 KB Output is correct
2 Correct 7 ms 5084 KB Output is correct
3 Correct 9 ms 4992 KB Output is correct
4 Correct 8 ms 4992 KB Output is correct
5 Correct 9 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 6 ms 5088 KB Output is correct
8 Correct 9 ms 4992 KB Output is correct
9 Correct 9 ms 4992 KB Output is correct
10 Correct 8 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 9 ms 4992 KB Output is correct
4 Correct 7 ms 4992 KB Output is correct
5 Correct 8 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 6 ms 5080 KB Output is correct
8 Correct 6 ms 5136 KB Output is correct
9 Correct 8 ms 4992 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 10 ms 4992 KB Output is correct
12 Correct 8 ms 4992 KB Output is correct
13 Correct 13 ms 4992 KB Output is correct
14 Correct 9 ms 4992 KB Output is correct
15 Correct 16 ms 4992 KB Output is correct
16 Correct 43 ms 5112 KB Output is correct
17 Correct 10 ms 4992 KB Output is correct
18 Correct 41 ms 5112 KB Output is correct
19 Correct 9 ms 4992 KB Output is correct
20 Correct 17 ms 5112 KB Output is correct
21 Correct 20 ms 5112 KB Output is correct
22 Correct 10 ms 5120 KB Output is correct
23 Correct 7 ms 4992 KB Output is correct
24 Correct 8 ms 4992 KB Output is correct
25 Correct 28 ms 5112 KB Output is correct
26 Correct 30 ms 5112 KB Output is correct
27 Correct 7 ms 5128 KB Output is correct
28 Correct 53 ms 5240 KB Output is correct
29 Correct 37 ms 5112 KB Output is correct
30 Correct 48 ms 5112 KB Output is correct
31 Correct 8 ms 4992 KB Output is correct
32 Correct 10 ms 5116 KB Output is correct
33 Correct 3 ms 4992 KB Output is correct
34 Correct 21 ms 5112 KB Output is correct
35 Correct 9 ms 4992 KB Output is correct
36 Correct 17 ms 4992 KB Output is correct
37 Correct 11 ms 4992 KB Output is correct
38 Correct 7 ms 5136 KB Output is correct
39 Correct 28 ms 5116 KB Output is correct
40 Correct 40 ms 5112 KB Output is correct
41 Correct 30 ms 5112 KB Output is correct
42 Correct 32 ms 5112 KB Output is correct
43 Correct 24 ms 5112 KB Output is correct
44 Correct 25 ms 5112 KB Output is correct
45 Correct 13 ms 5164 KB Output is correct
46 Correct 8 ms 4992 KB Output is correct
47 Correct 26 ms 5112 KB Output is correct
48 Correct 38 ms 5116 KB Output is correct
49 Correct 11 ms 4992 KB Output is correct
50 Correct 45 ms 5240 KB Output is correct
51 Correct 24 ms 5112 KB Output is correct
52 Correct 7 ms 4992 KB Output is correct
53 Correct 9 ms 5120 KB Output is correct
54 Correct 28 ms 5120 KB Output is correct
55 Correct 7 ms 4992 KB Output is correct
56 Correct 42 ms 5112 KB Output is correct
57 Correct 34 ms 5112 KB Output is correct
58 Correct 45 ms 5112 KB Output is correct
59 Correct 32 ms 5112 KB Output is correct
60 Correct 33 ms 5112 KB Output is correct
61 Correct 10 ms 4992 KB Output is correct
62 Correct 8 ms 4992 KB Output is correct
63 Correct 9 ms 4992 KB Output is correct
64 Correct 7 ms 5128 KB Output is correct
65 Correct 6 ms 5132 KB Output is correct
66 Correct 11 ms 4992 KB Output is correct
67 Correct 12 ms 4992 KB Output is correct
68 Correct 7 ms 4992 KB Output is correct
69 Correct 8 ms 5136 KB Output is correct
70 Correct 13 ms 4992 KB Output is correct
71 Partially correct 48 ms 5112 KB Partially correct - number of queries: 5238
72 Correct 9 ms 5100 KB Output is correct
73 Partially correct 49 ms 5252 KB Partially correct - number of queries: 5175
74 Partially correct 60 ms 5112 KB Partially correct - number of queries: 5202
75 Correct 11 ms 4992 KB Output is correct
76 Correct 45 ms 5132 KB Output is correct
77 Correct 57 ms 5240 KB Output is correct
78 Correct 11 ms 4992 KB Output is correct
79 Correct 27 ms 5116 KB Output is correct
80 Correct 41 ms 5112 KB Output is correct
81 Correct 40 ms 5112 KB Output is correct
82 Correct 50 ms 5112 KB Output is correct
83 Correct 9 ms 4992 KB Output is correct
84 Correct 46 ms 5112 KB Output is correct
85 Correct 50 ms 5112 KB Output is correct
86 Correct 6 ms 5072 KB Output is correct
87 Correct 9 ms 4992 KB Output is correct
88 Correct 9 ms 4992 KB Output is correct
89 Correct 8 ms 5248 KB Output is correct
90 Correct 9 ms 4992 KB Output is correct
91 Correct 10 ms 4992 KB Output is correct
92 Correct 9 ms 4992 KB Output is correct
93 Correct 9 ms 4992 KB Output is correct
94 Correct 11 ms 4992 KB Output is correct
95 Correct 10 ms 4992 KB Output is correct
96 Correct 11 ms 4992 KB Output is correct
97 Correct 8 ms 4992 KB Output is correct