Submission #420703

# Submission time Handle Problem Language Result Execution time Memory
420703 2021-06-08T13:25:21 Z Andyvanh1 The Big Prize (IOI17_prize) C++14
98.05 / 100
72 ms 2752 KB
#include <bits/stdc++.h>
#include "prize.h"
 
using namespace std;
 
#define vt vector
#define INF 0x3f3f3f3f
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,x) for(int (i) = 0;(i) < (x); (i)++)
#define MOD 1000000007
 
typedef vt<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
 
pii got[200005];
 
 
int fotal = 0;
 
int consum(int l, int r, int minl, int minr) {
    if (r < l)
        return -1;
 
    int mid = (l + r) >> 1;
    vi a;
 
    if (got[mid] != make_pair(-1, -1))
        a = {got[mid].first, got[mid].second};
    else
        a = ask(mid);
 
 
    if (a[0] + a[1] == fotal) {
        a[0] -= minl;
        a[1] -= minr;
        int x = -1, y = -1;
 
        if (a[0] != 0)
            x = consum(l, mid - 1, minl, a[1] + minr);
 
        if (x != -1)
            return x;
 
        if (a[1] != 0)
            y = consum(mid + 1, r, minl + a[0], minr);
 
        return max(x, y);
    } else if (a[0] + a[1] == 0) {
        return mid;
    } else {
        int cur1 = mid - 1;
        int cur2 = mid + 1;
        int has = 1;
 
        while (cur2 <= r) {
            if (got[cur2] != make_pair(-1, -1))
                a = {got[cur2].first, got[cur2].second};
            else
                a = ask(cur2);
 
            if (a[0] + a[1] == fotal) {
                int x = -1, y = -1;
 
                if (a[0] - minl - has != 0)
                    x = consum(l, mid - 1, minl, a[1] + has);
 
                if (x != -1)
                    return x;
 
                if (a[1] - minr != 0)
                    y = consum(cur2 + 1, r, a[0], minr);
 
                return max(x, y);
            } else if (a[0] + a[1] == 0) {
                return cur2;
            } else {
                cur2++;
                has++;
            }
        }
 
        while (cur1 >= l) {
            if (got[cur1] != make_pair(-1, -1))
                a = {got[cur1].first, got[cur1].second};
            else
                a = ask(cur1);
 
            if (a[0] + a[1] == fotal) {
                if (a[0] - minl != 0)
                    return consum(l, cur1 - 1, minl, a[1]);
                else
                    return -1;
            } else if (a[0] + a[1] == 0) {
                return cur1;
            } else {
                cur1--;
            }
 
        }
 
        return -1;
 
    }
}
 
int find_best(int n) {
    vi arr(n);
 
    for (int i = 0; i < n; i++) {
        got[i] = {-1, -1};
        arr[i] = i;
    }
 
    random_shuffle(all(arr));
 
    int k = sqrt(n) + 2;
 
    for (int i = 0; i < k; i++) {
        int j = arr[i];
        vi a = ask(j);
        got[j] = {a[0], a[1]};
 
        if (a[0] + a[1] == 0)
            return j;
 
        if (a[0] + a[1] > fotal)
            fotal = a[0] + a[1];
    }
 
    return consum(0, n - 1, 0, 0);
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2632 KB Output is correct
2 Correct 14 ms 2656 KB Output is correct
3 Correct 10 ms 2592 KB Output is correct
4 Correct 9 ms 2588 KB Output is correct
5 Correct 13 ms 2588 KB Output is correct
6 Correct 11 ms 2584 KB Output is correct
7 Correct 10 ms 2624 KB Output is correct
8 Correct 10 ms 2632 KB Output is correct
9 Correct 8 ms 2624 KB Output is correct
10 Correct 11 ms 2632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2636 KB Output is correct
2 Correct 12 ms 2632 KB Output is correct
3 Correct 10 ms 2596 KB Output is correct
4 Correct 11 ms 2632 KB Output is correct
5 Correct 9 ms 2632 KB Output is correct
6 Correct 8 ms 2648 KB Output is correct
7 Correct 12 ms 2632 KB Output is correct
8 Correct 11 ms 2632 KB Output is correct
9 Correct 9 ms 2592 KB Output is correct
10 Correct 12 ms 2632 KB Output is correct
11 Correct 12 ms 2636 KB Output is correct
12 Correct 8 ms 2584 KB Output is correct
13 Correct 16 ms 2584 KB Output is correct
14 Correct 3 ms 456 KB Output is correct
15 Correct 20 ms 2624 KB Output is correct
16 Correct 25 ms 2632 KB Output is correct
17 Correct 10 ms 2624 KB Output is correct
18 Correct 63 ms 2592 KB Output is correct
19 Correct 12 ms 2632 KB Output is correct
20 Correct 16 ms 1480 KB Output is correct
21 Correct 29 ms 2596 KB Output is correct
22 Correct 10 ms 2636 KB Output is correct
23 Correct 12 ms 2588 KB Output is correct
24 Correct 10 ms 2596 KB Output is correct
25 Correct 35 ms 2624 KB Output is correct
26 Correct 44 ms 2632 KB Output is correct
27 Correct 14 ms 2596 KB Output is correct
28 Correct 51 ms 2588 KB Output is correct
29 Correct 27 ms 2628 KB Output is correct
30 Correct 35 ms 2640 KB Output is correct
31 Correct 11 ms 2576 KB Output is correct
32 Correct 10 ms 2576 KB Output is correct
33 Correct 1 ms 200 KB Output is correct
34 Correct 27 ms 2588 KB Output is correct
35 Correct 14 ms 2600 KB Output is correct
36 Correct 24 ms 2596 KB Output is correct
37 Correct 8 ms 2640 KB Output is correct
38 Correct 13 ms 2588 KB Output is correct
39 Correct 32 ms 2592 KB Output is correct
40 Correct 42 ms 2596 KB Output is correct
41 Correct 33 ms 2596 KB Output is correct
42 Correct 43 ms 2592 KB Output is correct
43 Correct 36 ms 2624 KB Output is correct
44 Correct 16 ms 2636 KB Output is correct
45 Correct 28 ms 2592 KB Output is correct
46 Correct 8 ms 2652 KB Output is correct
47 Correct 30 ms 2588 KB Output is correct
48 Correct 22 ms 2644 KB Output is correct
49 Correct 16 ms 2636 KB Output is correct
50 Correct 58 ms 2572 KB Output is correct
51 Correct 20 ms 2580 KB Output is correct
52 Correct 10 ms 2576 KB Output is correct
53 Correct 16 ms 2588 KB Output is correct
54 Correct 47 ms 2592 KB Output is correct
55 Correct 12 ms 2624 KB Output is correct
56 Correct 65 ms 2584 KB Output is correct
57 Correct 53 ms 2632 KB Output is correct
58 Correct 47 ms 2584 KB Output is correct
59 Correct 32 ms 2632 KB Output is correct
60 Correct 29 ms 2632 KB Output is correct
61 Correct 15 ms 2572 KB Output is correct
62 Correct 16 ms 2704 KB Output is correct
63 Correct 16 ms 2632 KB Output is correct
64 Correct 11 ms 2624 KB Output is correct
65 Correct 8 ms 2680 KB Output is correct
66 Correct 16 ms 2576 KB Output is correct
67 Correct 16 ms 2572 KB Output is correct
68 Correct 11 ms 2596 KB Output is correct
69 Correct 15 ms 2624 KB Output is correct
70 Correct 9 ms 2588 KB Output is correct
71 Partially correct 55 ms 2632 KB Partially correct - number of queries: 5195
72 Correct 16 ms 2632 KB Output is correct
73 Partially correct 63 ms 2632 KB Partially correct - number of queries: 5134
74 Partially correct 52 ms 2632 KB Partially correct - number of queries: 5161
75 Correct 12 ms 2652 KB Output is correct
76 Correct 44 ms 2648 KB Output is correct
77 Correct 62 ms 2632 KB Output is correct
78 Correct 15 ms 2752 KB Output is correct
79 Correct 29 ms 2632 KB Output is correct
80 Correct 60 ms 2632 KB Output is correct
81 Correct 54 ms 2632 KB Output is correct
82 Correct 72 ms 2644 KB Output is correct
83 Correct 12 ms 2632 KB Output is correct
84 Correct 25 ms 2632 KB Output is correct
85 Correct 51 ms 2632 KB Output is correct
86 Correct 21 ms 2648 KB Output is correct
87 Correct 9 ms 2652 KB Output is correct
88 Correct 34 ms 2632 KB Output is correct
89 Correct 20 ms 2632 KB Output is correct
90 Correct 12 ms 2632 KB Output is correct
91 Correct 32 ms 2632 KB Output is correct
92 Correct 30 ms 2652 KB Output is correct
93 Correct 31 ms 2632 KB Output is correct
94 Correct 46 ms 2632 KB Output is correct
95 Correct 53 ms 2592 KB Output is correct
96 Correct 34 ms 2632 KB Output is correct
97 Correct 50 ms 2632 KB Output is correct