Submission #247373

# Submission time Handle Problem Language Result Execution time Memory
247373 2020-07-11T09:07:31 Z hhh07 The Big Prize (IOI17_prize) C++14
100 / 100
62 ms 5436 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <set>
#include <cmath>
#include <cstring>
#include "prize.h"
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll, ll> ii;

vi mem[(int)2e5 + 1];
bool done[(int)2e5 + 1];

vi pitaj(int idx){
    if (done[idx])
        return mem[idx];
    done[idx] = true;
    return mem[idx] = ask(idx);
}

int bin_search(int lijevo, int beg, int end, int maxi){
    if (beg > end)
        return -1;
    int l = beg, r = end;
    vi t;
    while(l < r){
        int mid = (l + r)/2;
        t = pitaj(mid);
        if (t[0] + t[1] == 0)
            return mid;
        if (t[0] + t[1] == maxi){
            if (lijevo - t[1])
                r = mid - 1;
            else
                l = mid + 1;
        }
        else
            r = mid;
    }
    
    while(end >= l){
        t = pitaj(l);
        if (t[0] + t[1] == 0)
            return l;
        if (t[0] + t[1] == maxi)
            break;
        l++;
    }
    if (mem[l][1] - mem[end + 1][1])
        return bin_search(mem[l][1], l + 1, end, maxi);
    return -1;
}


int find_best(int n){
    memset(done, 0, sizeof(done));
    int maxi = 0;
    int grupa = 460, br = n/460;
    int curr = 0;
    vi idx;
    for (int i = 0; i < grupa; i++){
        if (curr >= n)
            break;
        vi res = pitaj(curr);
        maxi = max(maxi, res[0] + res[1]);
        if (res[0] + res[1] == 0)
            return curr;
        idx.push_back(curr);
        if (i < (n%460))
            curr += br + 1;
        else
            curr += br;
        
    }
    done[n] = true; mem[n] = {maxi, 0}; idx.push_back(n);
    for (int i = 0; i < idx.size() - 1; i++){
        int x = idx[i], y = idx[i + 1];
        int res = -1;
        vi r;
        if (mem[x][0] + mem[x][1] < maxi){
            while(y >= x){
                r = pitaj(x);
                if (r[0] + r[1] == 0)
                    return x;
                if (r[0] + r[1] == maxi)
                    break;
                x++;
            }
        }
        if (mem[y][0] + mem[y][1] < maxi){
            while(y >= x){
                r = pitaj(y);
                if (r[0] + r[1] == 0)
                    return y;
                if (r[0] + r[1] == maxi)
                    break;
                y--;
            }
        }
        
        if (x <= y)
            if ((mem[x][1] - mem[y][1]) > 0)
                res = bin_search(mem[x][1], x + 1, y - 1, maxi);
        if (res != -1)
            return res;
    }
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:82:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < idx.size() - 1; i++){
                     ~~^~~~~~~~~~~~~~~~
prize.cpp:113:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 11 ms 5248 KB Output is correct
2 Correct 12 ms 5248 KB Output is correct
3 Correct 12 ms 5248 KB Output is correct
4 Correct 13 ms 5248 KB Output is correct
5 Correct 13 ms 5248 KB Output is correct
6 Correct 8 ms 5240 KB Output is correct
7 Correct 13 ms 5376 KB Output is correct
8 Correct 12 ms 5248 KB Output is correct
9 Correct 12 ms 5248 KB Output is correct
10 Correct 13 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 5324 KB Output is correct
2 Correct 12 ms 5248 KB Output is correct
3 Correct 12 ms 5248 KB Output is correct
4 Correct 10 ms 5332 KB Output is correct
5 Correct 13 ms 5248 KB Output is correct
6 Correct 8 ms 5376 KB Output is correct
7 Correct 14 ms 5248 KB Output is correct
8 Correct 14 ms 5240 KB Output is correct
9 Correct 12 ms 5248 KB Output is correct
10 Correct 13 ms 5248 KB Output is correct
11 Correct 14 ms 5240 KB Output is correct
12 Correct 12 ms 5240 KB Output is correct
13 Correct 13 ms 5240 KB Output is correct
14 Correct 15 ms 5248 KB Output is correct
15 Correct 17 ms 5240 KB Output is correct
16 Correct 40 ms 5344 KB Output is correct
17 Correct 13 ms 5216 KB Output is correct
18 Correct 52 ms 5368 KB Output is correct
19 Correct 12 ms 5248 KB Output is correct
20 Correct 23 ms 5248 KB Output is correct
21 Correct 29 ms 5244 KB Output is correct
22 Correct 11 ms 5332 KB Output is correct
23 Correct 12 ms 5248 KB Output is correct
24 Correct 10 ms 5240 KB Output is correct
25 Correct 36 ms 5240 KB Output is correct
26 Correct 30 ms 5368 KB Output is correct
27 Correct 10 ms 5276 KB Output is correct
28 Correct 40 ms 5368 KB Output is correct
29 Correct 33 ms 5240 KB Output is correct
30 Correct 10 ms 5324 KB Output is correct
31 Correct 13 ms 5248 KB Output is correct
32 Correct 13 ms 5240 KB Output is correct
33 Correct 7 ms 5248 KB Output is correct
34 Correct 19 ms 5292 KB Output is correct
35 Correct 14 ms 5248 KB Output is correct
36 Correct 20 ms 5248 KB Output is correct
37 Correct 11 ms 5240 KB Output is correct
38 Correct 14 ms 5248 KB Output is correct
39 Correct 30 ms 5248 KB Output is correct
40 Correct 55 ms 5368 KB Output is correct
41 Correct 41 ms 5248 KB Output is correct
42 Correct 41 ms 5344 KB Output is correct
43 Correct 29 ms 5344 KB Output is correct
44 Correct 28 ms 5408 KB Output is correct
45 Correct 24 ms 5248 KB Output is correct
46 Correct 14 ms 5240 KB Output is correct
47 Correct 33 ms 5240 KB Output is correct
48 Correct 36 ms 5244 KB Output is correct
49 Correct 18 ms 5248 KB Output is correct
50 Correct 62 ms 5368 KB Output is correct
51 Correct 30 ms 5248 KB Output is correct
52 Correct 21 ms 5240 KB Output is correct
53 Correct 14 ms 5260 KB Output is correct
54 Correct 33 ms 5296 KB Output is correct
55 Correct 12 ms 5248 KB Output is correct
56 Correct 47 ms 5368 KB Output is correct
57 Correct 25 ms 5412 KB Output is correct
58 Correct 50 ms 5296 KB Output is correct
59 Correct 39 ms 5272 KB Output is correct
60 Correct 48 ms 5368 KB Output is correct
61 Correct 12 ms 5248 KB Output is correct
62 Correct 11 ms 5228 KB Output is correct
63 Correct 12 ms 5248 KB Output is correct
64 Correct 15 ms 5248 KB Output is correct
65 Correct 15 ms 5248 KB Output is correct
66 Correct 28 ms 5240 KB Output is correct
67 Correct 14 ms 5248 KB Output is correct
68 Correct 21 ms 5248 KB Output is correct
69 Correct 18 ms 5248 KB Output is correct
70 Correct 13 ms 5240 KB Output is correct
71 Correct 56 ms 5368 KB Output is correct
72 Correct 13 ms 5248 KB Output is correct
73 Correct 50 ms 5368 KB Output is correct
74 Correct 30 ms 5436 KB Output is correct
75 Correct 13 ms 5248 KB Output is correct
76 Correct 61 ms 5368 KB Output is correct
77 Correct 45 ms 5372 KB Output is correct
78 Correct 16 ms 5248 KB Output is correct
79 Correct 34 ms 5248 KB Output is correct
80 Correct 60 ms 5368 KB Output is correct
81 Correct 57 ms 5368 KB Output is correct
82 Correct 46 ms 5368 KB Output is correct
83 Correct 14 ms 5248 KB Output is correct
84 Correct 36 ms 5368 KB Output is correct
85 Correct 51 ms 5368 KB Output is correct
86 Correct 18 ms 5368 KB Output is correct
87 Correct 13 ms 5248 KB Output is correct
88 Correct 15 ms 5248 KB Output is correct
89 Correct 22 ms 5248 KB Output is correct
90 Correct 12 ms 5268 KB Output is correct
91 Correct 16 ms 5248 KB Output is correct
92 Correct 23 ms 5248 KB Output is correct
93 Correct 25 ms 5248 KB Output is correct
94 Correct 23 ms 5368 KB Output is correct
95 Correct 26 ms 5248 KB Output is correct
96 Correct 27 ms 5248 KB Output is correct
97 Correct 19 ms 5248 KB Output is correct