Submission #430340

# Submission time Handle Problem Language Result Execution time Memory
430340 2021-06-16T13:02:31 Z 2fat2code The Big Prize (IOI17_prize) C++17
100 / 100
82 ms 6712 KB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
//#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int xmax = 500;
const int blocksize = 447;

int maxi = 0, cnt = 1, l[50000], r[50000], nrblockuri, asked[200005], bune[50000], viz[200005];
vector<int>remember[200005];

int find_best(int n) {
	nrblockuri = (n - 1)/ blocksize;
	for(int i=0;i<=nrblockuri;i++){
        l[i] = i*blocksize;
        r[i] = min(n-1, (i + 1) * blocksize - 1);
	}
	for(int i=0;i<=nrblockuri;i++){
        vector<int>arr = ask(l[i]);
        if(!(arr[0] + arr[1])){
            return l[i];
        }
        viz[l[i]] = 1;
        remember[l[i]] = arr;
        maxi = max(maxi, arr[0] + arr[1]);
	}
	for(int i=1;i<=min(50,n - 1);i++){
        vector<int>arr = ask(i);
        if(!(arr[0] + arr[1])){
            return i;
        }
        viz[i] = 1;
        remember[i] = arr;
        maxi = max(maxi, arr[0] + arr[1]);
	}
    for(int i=0;i<=nrblockuri;i++){
        while(l[i] <= r[i]){
            vector<int>rs;
            if(!viz[l[i]]){
                viz[l[i]] = 1;
                rs = ask(l[i]);
            }
            else{
                rs = remember[l[i]];
            }
            if(!(rs[0] + rs[1])){
                return l[i];
            }
            asked[l[i]] = rs[1];
            if((rs[0] + rs[1]) != maxi){
                l[i]++;
                bune[i]++;
            }
            else{
                break;
            }
        }
    }
    for(int i=0;i<=nrblockuri;i++){
        cnt += bune[i];
        if(l[i] <= r[i]){
            int nrfolosiri = 0;
            for(int j=i+1;j<=nrblockuri;j++){
                nrfolosiri += bune[j];
                if(l[j] != r[j] + 1){
                    nrfolosiri += asked[l[j]];
                    break;
                }
            }
            int ok = l[i];
            nrfolosiri = asked[l[i]] - nrfolosiri;
            for(int j=1;j<=nrfolosiri;j++){
                int le = ok + 1;
                int ri = r[i];
                ok = -1;
                int hahah = 0;
                while(le <= ri){
                    hahah ++;
                    int mid = le + (ri - le) / 2;
                    vector<int>rs;
                    if(viz[mid]){
                        rs = remember[mid];
                    }
                    else{
                        viz[mid] = 1;
                        rs = ask(mid);
                        remember[mid] = rs;
                    }
                    if((rs[0] + rs[1]) == maxi){
                        if(rs[0] >= cnt){
                            ri = mid - 1;
                        }
                        else{
                            le = mid + 1;
                        }
                    }
                    else{
                        if(!(rs[0] + rs[1])){
                            return mid;
                        }
                        ok = mid;
                        ri = mid - 1;
                    }
                }
                cnt++;
            }
        }
	}
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:120:1: warning: control reaches end of non-void function [-Wreturn-type]
  120 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 14 ms 6532 KB Output is correct
2 Correct 8 ms 6520 KB Output is correct
3 Correct 11 ms 6496 KB Output is correct
4 Correct 16 ms 6556 KB Output is correct
5 Correct 15 ms 6452 KB Output is correct
6 Correct 5 ms 4936 KB Output is correct
7 Correct 13 ms 6528 KB Output is correct
8 Correct 17 ms 6520 KB Output is correct
9 Correct 13 ms 6524 KB Output is correct
10 Correct 12 ms 6524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 6464 KB Output is correct
2 Correct 14 ms 6520 KB Output is correct
3 Correct 12 ms 6512 KB Output is correct
4 Correct 11 ms 6556 KB Output is correct
5 Correct 12 ms 6492 KB Output is correct
6 Correct 4 ms 4936 KB Output is correct
7 Correct 10 ms 6520 KB Output is correct
8 Correct 12 ms 6516 KB Output is correct
9 Correct 11 ms 6520 KB Output is correct
10 Correct 15 ms 6464 KB Output is correct
11 Correct 13 ms 6464 KB Output is correct
12 Correct 13 ms 6464 KB Output is correct
13 Correct 9 ms 6572 KB Output is correct
14 Correct 8 ms 5180 KB Output is correct
15 Correct 15 ms 6464 KB Output is correct
16 Correct 57 ms 6672 KB Output is correct
17 Correct 16 ms 6520 KB Output is correct
18 Correct 44 ms 6636 KB Output is correct
19 Correct 10 ms 6448 KB Output is correct
20 Correct 27 ms 5704 KB Output is correct
21 Correct 28 ms 6580 KB Output is correct
22 Correct 9 ms 6584 KB Output is correct
23 Correct 12 ms 6520 KB Output is correct
24 Correct 9 ms 6524 KB Output is correct
25 Correct 41 ms 6636 KB Output is correct
26 Correct 51 ms 6592 KB Output is correct
27 Correct 9 ms 6472 KB Output is correct
28 Correct 74 ms 6656 KB Output is correct
29 Correct 46 ms 6592 KB Output is correct
30 Correct 51 ms 6664 KB Output is correct
31 Correct 12 ms 6544 KB Output is correct
32 Correct 16 ms 6524 KB Output is correct
33 Correct 4 ms 4936 KB Output is correct
34 Correct 27 ms 6520 KB Output is correct
35 Correct 16 ms 6524 KB Output is correct
36 Correct 18 ms 6584 KB Output is correct
37 Correct 10 ms 6492 KB Output is correct
38 Correct 12 ms 6464 KB Output is correct
39 Correct 33 ms 6620 KB Output is correct
40 Correct 61 ms 6648 KB Output is correct
41 Correct 46 ms 6640 KB Output is correct
42 Correct 44 ms 6592 KB Output is correct
43 Correct 42 ms 6596 KB Output is correct
44 Correct 35 ms 6520 KB Output is correct
45 Correct 33 ms 6524 KB Output is correct
46 Correct 15 ms 6528 KB Output is correct
47 Correct 29 ms 6592 KB Output is correct
48 Correct 56 ms 6712 KB Output is correct
49 Correct 15 ms 6524 KB Output is correct
50 Correct 40 ms 6644 KB Output is correct
51 Correct 34 ms 6592 KB Output is correct
52 Correct 16 ms 6568 KB Output is correct
53 Correct 17 ms 6524 KB Output is correct
54 Correct 34 ms 6616 KB Output is correct
55 Correct 15 ms 6524 KB Output is correct
56 Correct 53 ms 6648 KB Output is correct
57 Correct 40 ms 6624 KB Output is correct
58 Correct 34 ms 6604 KB Output is correct
59 Correct 34 ms 6624 KB Output is correct
60 Correct 65 ms 6604 KB Output is correct
61 Correct 17 ms 6548 KB Output is correct
62 Correct 12 ms 6444 KB Output is correct
63 Correct 14 ms 6444 KB Output is correct
64 Correct 12 ms 6468 KB Output is correct
65 Correct 12 ms 6488 KB Output is correct
66 Correct 17 ms 6516 KB Output is correct
67 Correct 13 ms 6524 KB Output is correct
68 Correct 16 ms 5752 KB Output is correct
69 Correct 11 ms 6464 KB Output is correct
70 Correct 18 ms 6484 KB Output is correct
71 Correct 52 ms 6684 KB Output is correct
72 Correct 21 ms 6504 KB Output is correct
73 Correct 69 ms 6712 KB Output is correct
74 Correct 59 ms 6692 KB Output is correct
75 Correct 12 ms 6472 KB Output is correct
76 Correct 50 ms 6660 KB Output is correct
77 Correct 75 ms 6664 KB Output is correct
78 Correct 19 ms 6480 KB Output is correct
79 Correct 24 ms 6596 KB Output is correct
80 Correct 73 ms 6632 KB Output is correct
81 Correct 67 ms 6672 KB Output is correct
82 Correct 59 ms 6640 KB Output is correct
83 Correct 12 ms 6484 KB Output is correct
84 Correct 42 ms 6608 KB Output is correct
85 Correct 82 ms 6672 KB Output is correct
86 Correct 16 ms 6468 KB Output is correct
87 Correct 15 ms 6556 KB Output is correct
88 Correct 21 ms 6492 KB Output is correct
89 Correct 20 ms 6544 KB Output is correct
90 Correct 9 ms 6528 KB Output is correct
91 Correct 10 ms 6472 KB Output is correct
92 Correct 13 ms 6452 KB Output is correct
93 Correct 29 ms 6580 KB Output is correct
94 Correct 18 ms 6564 KB Output is correct
95 Correct 13 ms 6580 KB Output is correct
96 Correct 23 ms 6576 KB Output is correct
97 Correct 14 ms 6448 KB Output is correct