Submission #249634

# Submission time Handle Problem Language Result Execution time Memory
249634 2020-07-15T12:16:50 Z kostia244 The Big Prize (IOI17_prize) C++17
100 / 100
94 ms 5744 KB
#include "prize.h"
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
map<int, vector<int>> memo;
int qry = 0;
vector<int> fffff(int p) {
	if(memo.count(p)) return memo[p];
	return memo[p] = ask(p);
}
#define ask fffff
int cb = 1<<30, cg;
vector<int> cnt(20, 0);
vi findgood(vi vals, int cl, int cc, int cr, int _Dep = 0) {
	if(vals.empty() || !cc) return {};
	if(vals.size() == cc) return vals;
	int l = vals.size()/2;
	int r = l+1, go = -1;
	cnt[_Dep]++;
	//for(auto i : vals) cout << i << " "; cout << cl << " " << cc << " " << cr << "::" << endl;
	vi gg, t;
	while(l >= 0 || r < vals.size()) {
		if(l >= 0) {
			t = ask(vals[l]);
			if(t[0] + t[1] == cg) {
				go = l;
				break;
			}
			gg.push_back(vals[l--]);
		}
		if(r < vals.size()) {
			t = ask(vals[r]);
			if(t[0] + t[1] == cg) {
				go = r;
				break;
			}
			gg.push_back(vals[r++]);
		}
	}
	if(l < 0 && r >= vals.size()) return gg;
	vi vl, vr;
	for(int i = 0; i < vals.size(); i++) {
		if(i == go) continue;
		if(i <= l) vl.push_back(vals[i]);
		if(i >= r) vr.push_back(vals[i]);
	}
	t[0] -= cl;
	t[1] -= cr;
	//cout << vals.size() << " to " << vl.size() << " + " << vr.size() << " " << _Dep << " " << cl << " / " << cc << " / " << cr << endl;
	//cout << cl << " " << cc << " " << cr << " " << gg.size()+vl.size()+vr.size() << " " << vals.size() << endl;
	for(auto &i : findgood(vl, cl, t[0], cr+t[1], _Dep+1)) gg.push_back(i);
	for(auto &i : findgood(vr, cl+t[0], t[1], cr, _Dep+1)) gg.push_back(i);
	return gg;
}
int findbad(int l, int r) {
	if(r-l < 50) {
		int ans = 0;
		while(l < r) {
			ans = max(ans, ask(l)[0] + ask(l)[1]);
			l++;
		}
		return ans;
	}
	int mid = (l+r)/2;
	if(ask(mid)[0] < ask(mid)[1] && l < mid) return findbad(l, mid);
	else return findbad(mid, r);
}
int solve(vector<int> p) {
	vi g, pg;
	if(p.size() > 1000) { 
		cg = findbad(0, p.size());
		p = findgood(p, 0, cg , 0);
	}
	//for(auto i : p) cout << i << " is good.\n";
	//for(auto i : cnt) cout << i << " ";cout << endl;
	for(auto i : p) {
		std::vector<int> res = ask(i);
		if(res[0] + res[1] == 0)
			return i;
	}
}
int find_best(int n) {
	vi t;
	for(int i = 0; i < n; i++) t.push_back(i);
	return solve(t);
}

Compilation message

prize.cpp: In function 'vi findgood(vi, int, int, int, int)':
prize.cpp:17:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(vals.size() == cc) return vals;
     ~~~~~~~~~~~~^~~~~
prize.cpp:23:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(l >= 0 || r < vals.size()) {
                  ~~^~~~~~~~~~~~~
prize.cpp:32:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(r < vals.size()) {
      ~~^~~~~~~~~~~~~
prize.cpp:41:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(l < 0 && r >= vals.size()) return gg;
              ~~^~~~~~~~~~~~~~
prize.cpp:43:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < vals.size(); i++) {
                 ~~^~~~~~~~~~~~~
prize.cpp: In function 'int solve(std::vector<int>)':
prize.cpp:82:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5108 KB Output is correct
2 Correct 7 ms 5100 KB Output is correct
3 Correct 7 ms 5100 KB Output is correct
4 Correct 6 ms 5100 KB Output is correct
5 Correct 7 ms 5100 KB Output is correct
6 Correct 7 ms 5108 KB Output is correct
7 Correct 7 ms 5108 KB Output is correct
8 Correct 6 ms 5168 KB Output is correct
9 Correct 7 ms 5100 KB Output is correct
10 Correct 7 ms 5108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5176 KB Output is correct
2 Correct 7 ms 5108 KB Output is correct
3 Correct 7 ms 5100 KB Output is correct
4 Correct 7 ms 5100 KB Output is correct
5 Correct 7 ms 5108 KB Output is correct
6 Correct 7 ms 5108 KB Output is correct
7 Correct 7 ms 5100 KB Output is correct
8 Correct 7 ms 5108 KB Output is correct
9 Correct 7 ms 5108 KB Output is correct
10 Correct 7 ms 5108 KB Output is correct
11 Correct 16 ms 5228 KB Output is correct
12 Correct 17 ms 5100 KB Output is correct
13 Correct 15 ms 5172 KB Output is correct
14 Correct 23 ms 1016 KB Output is correct
15 Correct 69 ms 5676 KB Output is correct
16 Correct 49 ms 5684 KB Output is correct
17 Correct 73 ms 5608 KB Output is correct
18 Correct 80 ms 5612 KB Output is correct
19 Correct 58 ms 5608 KB Output is correct
20 Correct 38 ms 3056 KB Output is correct
21 Correct 64 ms 5612 KB Output is correct
22 Correct 50 ms 5740 KB Output is correct
23 Correct 11 ms 5108 KB Output is correct
24 Correct 15 ms 5100 KB Output is correct
25 Correct 63 ms 5592 KB Output is correct
26 Correct 56 ms 5608 KB Output is correct
27 Correct 10 ms 5100 KB Output is correct
28 Correct 70 ms 5612 KB Output is correct
29 Correct 51 ms 5480 KB Output is correct
30 Correct 63 ms 5740 KB Output is correct
31 Correct 65 ms 5612 KB Output is correct
32 Correct 17 ms 5228 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 71 ms 5608 KB Output is correct
35 Correct 12 ms 5108 KB Output is correct
36 Correct 72 ms 5612 KB Output is correct
37 Correct 15 ms 5176 KB Output is correct
38 Correct 11 ms 5108 KB Output is correct
39 Correct 69 ms 5736 KB Output is correct
40 Correct 70 ms 5612 KB Output is correct
41 Correct 78 ms 5616 KB Output is correct
42 Correct 73 ms 5676 KB Output is correct
43 Correct 84 ms 5688 KB Output is correct
44 Correct 61 ms 5608 KB Output is correct
45 Correct 57 ms 5612 KB Output is correct
46 Correct 61 ms 5608 KB Output is correct
47 Correct 82 ms 5588 KB Output is correct
48 Correct 64 ms 5612 KB Output is correct
49 Correct 78 ms 5744 KB Output is correct
50 Correct 75 ms 5612 KB Output is correct
51 Correct 76 ms 5600 KB Output is correct
52 Correct 78 ms 5612 KB Output is correct
53 Correct 11 ms 5100 KB Output is correct
54 Correct 78 ms 5612 KB Output is correct
55 Correct 77 ms 5612 KB Output is correct
56 Correct 73 ms 5608 KB Output is correct
57 Correct 49 ms 5688 KB Output is correct
58 Correct 67 ms 5612 KB Output is correct
59 Correct 73 ms 5640 KB Output is correct
60 Correct 75 ms 5688 KB Output is correct
61 Correct 11 ms 5108 KB Output is correct
62 Correct 11 ms 5108 KB Output is correct
63 Correct 10 ms 5236 KB Output is correct
64 Correct 11 ms 5084 KB Output is correct
65 Correct 8 ms 5100 KB Output is correct
66 Correct 12 ms 5104 KB Output is correct
67 Correct 12 ms 5100 KB Output is correct
68 Correct 12 ms 5100 KB Output is correct
69 Correct 12 ms 5100 KB Output is correct
70 Correct 9 ms 5100 KB Output is correct
71 Correct 65 ms 5612 KB Output is correct
72 Correct 15 ms 5228 KB Output is correct
73 Correct 79 ms 5532 KB Output is correct
74 Correct 64 ms 5612 KB Output is correct
75 Correct 10 ms 5108 KB Output is correct
76 Correct 73 ms 5480 KB Output is correct
77 Correct 65 ms 5612 KB Output is correct
78 Correct 19 ms 5228 KB Output is correct
79 Correct 40 ms 5356 KB Output is correct
80 Correct 68 ms 5740 KB Output is correct
81 Correct 83 ms 5616 KB Output is correct
82 Correct 94 ms 5608 KB Output is correct
83 Correct 9 ms 5160 KB Output is correct
84 Correct 54 ms 5592 KB Output is correct
85 Correct 63 ms 5608 KB Output is correct
86 Correct 17 ms 5236 KB Output is correct
87 Correct 10 ms 5108 KB Output is correct
88 Correct 17 ms 5224 KB Output is correct
89 Correct 17 ms 5228 KB Output is correct
90 Correct 10 ms 5108 KB Output is correct
91 Correct 14 ms 5236 KB Output is correct
92 Correct 15 ms 5228 KB Output is correct
93 Correct 13 ms 5108 KB Output is correct
94 Correct 13 ms 5108 KB Output is correct
95 Correct 14 ms 5108 KB Output is correct
96 Correct 12 ms 5108 KB Output is correct
97 Correct 6 ms 5108 KB Output is correct