Submission #250274

# Submission time Handle Problem Language Result Execution time Memory
250274 2020-07-17T10:27:55 Z fedoseevtimofey The Big Prize (IOI17_prize) C++14
97.63 / 100
71 ms 896 KB
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

#include "prize.h"

int find_best(int n) {
  map <int, vector <int>> mem;
  int cnt = 0;
  auto my_ask = [&] (int i) {
    if (!mem.count(i)) {
      ++cnt;
      assert(cnt <= 10000);
      mem[i] = ask(i);
    }
    return mem[i];
  };
  function <int(int, int)> rec = [&] (int l, int r) {
    if (l > r) return -1;
    auto f = my_ask(l);
    if (f[0] + f[1] == 0) return l;
    auto s = my_ask(r);
    if (s[0] + s[1] == 0) return r;
    bool fl = false;
    if (f[0] + f[1] != s[0] + s[1]) fl = true;
    else if (f[1] - s[1] > 0) fl = true;
    if (fl && l != r) {
      int m = (l + r) >> 1;
      int x = -1;
      if (m < r) x = rec(l, m);
      if (x != -1) return x;
      if (m > l) x = rec(m, r);
      return x;
    } else {
      return -1;
    }
  };
  int ans = rec(0, n - 1);
  return ans;
}   

#ifdef LOCAL
const int max_q = 10000;
int n;
int query_count = 0;
vector<int> g;
vector<vector<int> > rank_count;

vector<int> ask(int i) {
	query_count++;
	if(query_count > max_q) {
		cerr << "Query limit exceeded" << endl;
		exit(0);
	}

	if(i < 0 || i >= n) {
		cerr << "Bad index: " << i << endl;
		exit(0);
	}

	vector<int> res(2);
	res[0] = rank_count[g[i] - 1][i + 1];
	res[1] = rank_count[g[i] - 1][n] - res[0];
	return res;
}
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  cin >> n;
	g.resize(n);
	for(int i = 0; i < n; i++) {
		cin >> g[i];
		if(g[i] < 1) {
			cerr << "Invalid rank " << g[i] << " at index " << i << endl;
			exit(0);
		}
	}
	int max_rank = *max_element(g.begin(), g.end());
  rank_count.resize(max_rank + 1, vector <int> (n + 1, 0));
	for(int r = 0; r <= max_rank; r++) {
		for(int i = 1; i <= n; i++) {
			rank_count[r][i] = rank_count[r][i - 1];
			if(g[i - 1] == r)
			  rank_count[r][i]++;
		}
	}
	for(int i = 0; i <= n; i++)
		for(int r = 1; r <= max_rank; r++)
			rank_count[r][i] += rank_count[r - 1][i];
	int res = find_best(n);
	cout << res << endl << "Query count: " << query_count << endl;
	return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 392 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 14 ms 384 KB Output is correct
16 Correct 33 ms 760 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Partially correct 46 ms 888 KB Partially correct - number of queries: 5068
19 Correct 0 ms 368 KB Output is correct
20 Correct 14 ms 384 KB Output is correct
21 Correct 17 ms 504 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 23 ms 636 KB Output is correct
26 Correct 35 ms 632 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 63 ms 760 KB Output is correct
29 Correct 21 ms 720 KB Output is correct
30 Partially correct 45 ms 888 KB Partially correct - number of queries: 5022
31 Correct 1 ms 256 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 22 ms 504 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 11 ms 376 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 28 ms 504 KB Output is correct
40 Correct 61 ms 760 KB Output is correct
41 Correct 29 ms 632 KB Output is correct
42 Correct 25 ms 632 KB Output is correct
43 Correct 40 ms 632 KB Output is correct
44 Correct 29 ms 504 KB Output is correct
45 Correct 26 ms 504 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 24 ms 504 KB Output is correct
48 Correct 27 ms 760 KB Output is correct
49 Correct 5 ms 376 KB Output is correct
50 Partially correct 52 ms 896 KB Partially correct - number of queries: 5070
51 Correct 26 ms 504 KB Output is correct
52 Correct 1 ms 256 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 31 ms 540 KB Output is correct
55 Correct 1 ms 256 KB Output is correct
56 Partially correct 52 ms 888 KB Partially correct - number of queries: 5069
57 Correct 34 ms 760 KB Output is correct
58 Correct 36 ms 744 KB Output is correct
59 Correct 31 ms 632 KB Output is correct
60 Correct 26 ms 632 KB Output is correct
61 Correct 2 ms 376 KB Output is correct
62 Correct 1 ms 256 KB Output is correct
63 Correct 2 ms 376 KB Output is correct
64 Correct 2 ms 376 KB Output is correct
65 Correct 1 ms 360 KB Output is correct
66 Correct 1 ms 256 KB Output is correct
67 Correct 1 ms 256 KB Output is correct
68 Correct 1 ms 256 KB Output is correct
69 Correct 1 ms 256 KB Output is correct
70 Correct 1 ms 256 KB Output is correct
71 Correct 68 ms 888 KB Output is correct
72 Correct 6 ms 400 KB Output is correct
73 Correct 71 ms 760 KB Output is correct
74 Correct 46 ms 760 KB Output is correct
75 Correct 2 ms 384 KB Output is correct
76 Correct 48 ms 800 KB Output is correct
77 Partially correct 47 ms 888 KB Partially correct - number of queries: 5216
78 Correct 6 ms 384 KB Output is correct
79 Correct 37 ms 588 KB Output is correct
80 Partially correct 53 ms 888 KB Partially correct - number of queries: 5237
81 Partially correct 56 ms 828 KB Partially correct - number of queries: 5218
82 Partially correct 50 ms 816 KB Partially correct - number of queries: 5216
83 Correct 2 ms 384 KB Output is correct
84 Correct 49 ms 784 KB Output is correct
85 Partially correct 53 ms 876 KB Partially correct - number of queries: 5233
86 Correct 9 ms 384 KB Output is correct
87 Correct 5 ms 384 KB Output is correct
88 Correct 7 ms 376 KB Output is correct
89 Correct 8 ms 384 KB Output is correct
90 Correct 3 ms 384 KB Output is correct
91 Correct 5 ms 384 KB Output is correct
92 Correct 1 ms 256 KB Output is correct
93 Correct 6 ms 384 KB Output is correct
94 Correct 8 ms 384 KB Output is correct
95 Correct 4 ms 384 KB Output is correct
96 Correct 8 ms 384 KB Output is correct
97 Correct 0 ms 256 KB Output is correct