Submission #789357

# Submission time Handle Problem Language Result Execution time Memory
789357 2023-07-21T09:44:27 Z enerelt14 The Big Prize (IOI17_prize) C++14
100 / 100
62 ms 11360 KB
#include "prize.h"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
#define pb push_back

int val, B, y;
vector<int> non_lolipop, x, L;

vector<vector<int>> memo;
vector<int> K(int i) {
	if(i >= (int)memo.size()) exit(0);
	if(memo[i][0] != -1) return memo[i];
	return memo[i] = ask(i);
}

void find(int l, int r){
	if (l > r)return;
	if(K(l)[0] + K(l)[1] != val) {
		non_lolipop.pb(l);
		find(l + 1, r);
		return;
	}
	if (K(l)[1] == y)return;
	int bl = l, br = r;
	while (bl != br){
		int bm = (bl + br) / 2;
		if (K(bm) == K(l)) {
			bl = bm + 1;
		} else {
			br = bm;
		}
	}
	find(bl, r);
}

int find_best(int n){
	memo.resize(n, {-1, -1});
	B = max(1, n / 472);
	for (int i = 0; i < n; i += B){
		x = K(i);
		val = max(val, x[0] + x[1]);
	}
	for (int i = 0; i < n; i += B){
		for (int j = i; j < i + B && j < n; j++){
			x = K(j);
			if (x[0] + x[1] != val){
				non_lolipop.pb(j);
				continue;
			}
			L.pb(j);
			break;
		}
	}
	for (int i = 0; i < (int)L.size(); i++){
		if (i + 1 == (int)L.size()){
			x = K(L[i]);
			y = max(0, n - (L[i] / B + 1) * B);
		}else{
			y = B * (L[i + 1] / B - L[i] / B - 1) + L[i + 1] % B;
			x = K(L[i]);
			vector<int> z = K(L[i + 1]);
			y += z[1];
		}
		find(L[i], min(n - 1, L[i] / B * B + B - 1));
	}
	for (int i = 0; i < non_lolipop.size(); i++){
		x = K(non_lolipop[i]);
		if (x[0] + x[1] == 0)return non_lolipop[i];
	}
	return 0;
}

Compilation message

prize.cpp: In function 'int find_best(int)':
prize.cpp:83:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |  for (int i = 0; i < non_lolipop.size(); i++){
      |                  ~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 11276 KB Output is correct
2 Correct 12 ms 11252 KB Output is correct
3 Correct 12 ms 11264 KB Output is correct
4 Correct 11 ms 11272 KB Output is correct
5 Correct 15 ms 11208 KB Output is correct
6 Correct 12 ms 11176 KB Output is correct
7 Correct 11 ms 11212 KB Output is correct
8 Correct 11 ms 11276 KB Output is correct
9 Correct 12 ms 11268 KB Output is correct
10 Correct 14 ms 11228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 11264 KB Output is correct
2 Correct 12 ms 11272 KB Output is correct
3 Correct 12 ms 11188 KB Output is correct
4 Correct 15 ms 11256 KB Output is correct
5 Correct 15 ms 11268 KB Output is correct
6 Correct 16 ms 11164 KB Output is correct
7 Correct 11 ms 11316 KB Output is correct
8 Correct 13 ms 11220 KB Output is correct
9 Correct 10 ms 11276 KB Output is correct
10 Correct 16 ms 11324 KB Output is correct
11 Correct 17 ms 11260 KB Output is correct
12 Correct 13 ms 11164 KB Output is correct
13 Correct 14 ms 11168 KB Output is correct
14 Correct 10 ms 1360 KB Output is correct
15 Correct 49 ms 11216 KB Output is correct
16 Correct 25 ms 11268 KB Output is correct
17 Correct 30 ms 11272 KB Output is correct
18 Correct 41 ms 11216 KB Output is correct
19 Correct 49 ms 11168 KB Output is correct
20 Correct 24 ms 5788 KB Output is correct
21 Correct 30 ms 11272 KB Output is correct
22 Correct 41 ms 11172 KB Output is correct
23 Correct 10 ms 11316 KB Output is correct
24 Correct 16 ms 11156 KB Output is correct
25 Correct 49 ms 11164 KB Output is correct
26 Correct 31 ms 11268 KB Output is correct
27 Correct 11 ms 11260 KB Output is correct
28 Correct 36 ms 11184 KB Output is correct
29 Correct 22 ms 11276 KB Output is correct
30 Correct 50 ms 11156 KB Output is correct
31 Correct 53 ms 11208 KB Output is correct
32 Correct 16 ms 11312 KB Output is correct
33 Correct 2 ms 208 KB Output is correct
34 Correct 48 ms 11160 KB Output is correct
35 Correct 11 ms 11216 KB Output is correct
36 Correct 55 ms 11152 KB Output is correct
37 Correct 17 ms 11252 KB Output is correct
38 Correct 14 ms 11164 KB Output is correct
39 Correct 43 ms 11252 KB Output is correct
40 Correct 33 ms 11164 KB Output is correct
41 Correct 62 ms 11168 KB Output is correct
42 Correct 56 ms 11188 KB Output is correct
43 Correct 39 ms 11172 KB Output is correct
44 Correct 49 ms 11156 KB Output is correct
45 Correct 30 ms 11284 KB Output is correct
46 Correct 45 ms 11248 KB Output is correct
47 Correct 51 ms 11252 KB Output is correct
48 Correct 49 ms 11216 KB Output is correct
49 Correct 53 ms 11248 KB Output is correct
50 Correct 38 ms 11168 KB Output is correct
51 Correct 55 ms 11252 KB Output is correct
52 Correct 40 ms 11268 KB Output is correct
53 Correct 14 ms 11192 KB Output is correct
54 Correct 58 ms 11248 KB Output is correct
55 Correct 56 ms 11156 KB Output is correct
56 Correct 49 ms 11248 KB Output is correct
57 Correct 36 ms 11168 KB Output is correct
58 Correct 50 ms 11168 KB Output is correct
59 Correct 43 ms 11160 KB Output is correct
60 Correct 40 ms 11160 KB Output is correct
61 Correct 20 ms 11160 KB Output is correct
62 Correct 15 ms 11244 KB Output is correct
63 Correct 16 ms 11252 KB Output is correct
64 Correct 13 ms 11168 KB Output is correct
65 Correct 15 ms 11252 KB Output is correct
66 Correct 15 ms 11260 KB Output is correct
67 Correct 18 ms 11172 KB Output is correct
68 Correct 14 ms 11132 KB Output is correct
69 Correct 22 ms 11264 KB Output is correct
70 Correct 18 ms 11276 KB Output is correct
71 Correct 51 ms 11152 KB Output is correct
72 Correct 15 ms 11272 KB Output is correct
73 Correct 47 ms 11272 KB Output is correct
74 Correct 49 ms 11216 KB Output is correct
75 Correct 12 ms 11268 KB Output is correct
76 Correct 37 ms 11268 KB Output is correct
77 Correct 35 ms 11264 KB Output is correct
78 Correct 20 ms 11256 KB Output is correct
79 Correct 30 ms 11216 KB Output is correct
80 Correct 47 ms 11152 KB Output is correct
81 Correct 52 ms 11216 KB Output is correct
82 Correct 49 ms 11268 KB Output is correct
83 Correct 12 ms 11272 KB Output is correct
84 Correct 33 ms 11360 KB Output is correct
85 Correct 48 ms 11216 KB Output is correct
86 Correct 19 ms 11216 KB Output is correct
87 Correct 14 ms 11276 KB Output is correct
88 Correct 17 ms 11232 KB Output is correct
89 Correct 19 ms 11216 KB Output is correct
90 Correct 15 ms 11268 KB Output is correct
91 Correct 12 ms 11280 KB Output is correct
92 Correct 17 ms 11216 KB Output is correct
93 Correct 22 ms 11272 KB Output is correct
94 Correct 15 ms 11272 KB Output is correct
95 Correct 21 ms 11216 KB Output is correct
96 Correct 14 ms 11268 KB Output is correct
97 Correct 18 ms 11216 KB Output is correct