Submission #251493

# Submission time Handle Problem Language Result Execution time Memory
251493 2020-07-21T13:30:28 Z quocnguyen1012 The Big Prize (IOI17_prize) C++14
97.63 / 100
108 ms 924 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 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 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
# 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 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 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 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 4 ms 384 KB Output is correct
15 Correct 11 ms 384 KB Output is correct
16 Correct 41 ms 760 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Partially correct 55 ms 888 KB Partially correct - number of queries: 5068
19 Correct 1 ms 256 KB Output is correct
20 Correct 12 ms 512 KB Output is correct
21 Correct 26 ms 504 KB Output is correct
22 Correct 3 ms 412 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 26 ms 632 KB Output is correct
26 Correct 26 ms 632 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 64 ms 840 KB Output is correct
29 Correct 60 ms 632 KB Output is correct
30 Partially correct 46 ms 888 KB Partially correct - number of queries: 5022
31 Correct 1 ms 256 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 9 ms 524 KB Output is correct
35 Correct 2 ms 256 KB Output is correct
36 Correct 15 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 32 ms 504 KB Output is correct
40 Correct 41 ms 760 KB Output is correct
41 Correct 32 ms 632 KB Output is correct
42 Correct 39 ms 664 KB Output is correct
43 Correct 38 ms 632 KB Output is correct
44 Correct 20 ms 504 KB Output is correct
45 Correct 15 ms 508 KB Output is correct
46 Correct 1 ms 256 KB Output is correct
47 Correct 20 ms 504 KB Output is correct
48 Correct 35 ms 760 KB Output is correct
49 Correct 4 ms 384 KB Output is correct
50 Partially correct 61 ms 892 KB Partially correct - number of queries: 5070
51 Correct 12 ms 540 KB Output is correct
52 Correct 1 ms 256 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 25 ms 632 KB Output is correct
55 Correct 1 ms 256 KB Output is correct
56 Partially correct 53 ms 888 KB Partially correct - number of queries: 5069
57 Correct 37 ms 760 KB Output is correct
58 Correct 33 ms 760 KB Output is correct
59 Correct 36 ms 724 KB Output is correct
60 Correct 27 ms 632 KB Output is correct
61 Correct 2 ms 384 KB Output is correct
62 Correct 1 ms 256 KB Output is correct
63 Correct 2 ms 384 KB Output is correct
64 Correct 2 ms 384 KB Output is correct
65 Correct 1 ms 256 KB Output is correct
66 Correct 1 ms 256 KB Output is correct
67 Correct 1 ms 256 KB Output is correct
68 Correct 0 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 64 ms 888 KB Output is correct
72 Correct 7 ms 384 KB Output is correct
73 Correct 54 ms 756 KB Output is correct
74 Correct 53 ms 848 KB Output is correct
75 Correct 3 ms 384 KB Output is correct
76 Correct 43 ms 760 KB Output is correct
77 Partially correct 108 ms 888 KB Partially correct - number of queries: 5216
78 Correct 5 ms 384 KB Output is correct
79 Correct 22 ms 632 KB Output is correct
80 Partially correct 59 ms 924 KB Partially correct - number of queries: 5237
81 Partially correct 56 ms 888 KB Partially correct - number of queries: 5218
82 Partially correct 49 ms 888 KB Partially correct - number of queries: 5216
83 Correct 2 ms 384 KB Output is correct
84 Correct 60 ms 760 KB Output is correct
85 Partially correct 49 ms 888 KB Partially correct - number of queries: 5233
86 Correct 6 ms 384 KB Output is correct
87 Correct 3 ms 392 KB Output is correct
88 Correct 11 ms 384 KB Output is correct
89 Correct 8 ms 384 KB Output is correct
90 Correct 2 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 4 ms 384 KB Output is correct
94 Correct 4 ms 384 KB Output is correct
95 Correct 4 ms 384 KB Output is correct
96 Correct 5 ms 384 KB Output is correct
97 Correct 1 ms 256 KB Output is correct