Submission #565893

# Submission time Handle Problem Language Result Execution time Memory
565893 2022-05-21T13:47:37 Z hoanghq2004 The Big Prize (IOI17_prize) C++14
100 / 100
386 ms 6144 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "prize.h"

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
//
//static const int max_q = 10000;
//static int n;
//static int query_count = 0;
//static vector<int> g;
//static 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 find_best(int n) {
    int tot = 0;
    srand(time(nullptr));
    int m = min(n, 10);
    vector <int> used(n, 0);
    vector <vector <int>> ans(n);
    auto get = [&](int i) {
        if (ans[i].size()) return ans[i];
        ans[i] = ask(i);
        return ans[i];
    };
    while (m--) {
        int i = rand() % n;
        while (used[i]) i = rand() % n;
        used[i] = 1;
        vector <int> cur = get(i);
        tot = max(tot, cur[0] + cur[1]);
    }
    map <int, map <int, int>> mp;
    function <int(int, int)> divide = [&](int L, int R) {
        if (L > R) return -1;
        int mid = L + R >> 1;
        for (auto [_, S]: mp) {
            auto rgt = S.upper_bound(mid);
            auto lft = rgt;
            if (rgt != S.end() && lft != S.begin()) {
                --lft;
                if (lft -> second == rgt -> second) return -1;
            }
        }
        if (get(mid)[0] + get(mid)[1] == 0) return mid;
        mp[get(mid)[0] + get(mid)[1]][mid] = get(mid)[0];
        int ans;
        if (rand() % 2) {
            ans = divide(L, mid - 1);
            if (ans == -1) ans = divide(mid + 1, R);
        } else {
            ans = divide(mid + 1, R);
            if (ans == -1) ans = divide(L, mid - 1);
        }
        return ans;
    };
    return divide(0, n - 1);
}

//
//int main() {
////    freopen("test.inp", "r", stdin);
//	cin >> n;
//
//	g.resize(n);
//	int id = rand() % n;
////	cout << id << "aaa\n";
//	for(int i = 0; i < n; i++) {
//		cin >> g[i];
////        if (i == id) g[i] = 1;
////        else g[i] = 2;
//		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;
//}

Compilation message

prize.cpp: In lambda function:
prize.cpp:59:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |         int mid = L + R >> 1;
      |                   ~~^~~
prize.cpp:60:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   60 |         for (auto [_, S]: mp) {
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5796 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 4 ms 5704 KB Output is correct
4 Correct 3 ms 5796 KB Output is correct
5 Correct 3 ms 5660 KB Output is correct
6 Correct 3 ms 5712 KB Output is correct
7 Correct 4 ms 5800 KB Output is correct
8 Correct 4 ms 5792 KB Output is correct
9 Correct 3 ms 5784 KB Output is correct
10 Correct 3 ms 5712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5704 KB Output is correct
2 Correct 4 ms 5660 KB Output is correct
3 Correct 3 ms 5780 KB Output is correct
4 Correct 3 ms 5796 KB Output is correct
5 Correct 3 ms 5712 KB Output is correct
6 Correct 3 ms 5712 KB Output is correct
7 Correct 3 ms 5712 KB Output is correct
8 Correct 3 ms 5796 KB Output is correct
9 Correct 3 ms 5664 KB Output is correct
10 Correct 5 ms 5712 KB Output is correct
11 Correct 4 ms 5800 KB Output is correct
12 Correct 7 ms 5712 KB Output is correct
13 Correct 11 ms 5776 KB Output is correct
14 Correct 4 ms 848 KB Output is correct
15 Correct 8 ms 5880 KB Output is correct
16 Correct 20 ms 5840 KB Output is correct
17 Correct 85 ms 5932 KB Output is correct
18 Correct 33 ms 5860 KB Output is correct
19 Correct 137 ms 5968 KB Output is correct
20 Correct 40 ms 3208 KB Output is correct
21 Correct 43 ms 5836 KB Output is correct
22 Correct 40 ms 5888 KB Output is correct
23 Correct 5 ms 5852 KB Output is correct
24 Correct 10 ms 5788 KB Output is correct
25 Correct 59 ms 5836 KB Output is correct
26 Correct 89 ms 6072 KB Output is correct
27 Correct 4 ms 5792 KB Output is correct
28 Correct 54 ms 5900 KB Output is correct
29 Correct 103 ms 5956 KB Output is correct
30 Correct 57 ms 5968 KB Output is correct
31 Correct 14 ms 5784 KB Output is correct
32 Correct 10 ms 5712 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 25 ms 5856 KB Output is correct
35 Correct 5 ms 5796 KB Output is correct
36 Correct 21 ms 5788 KB Output is correct
37 Correct 4 ms 5800 KB Output is correct
38 Correct 3 ms 5792 KB Output is correct
39 Correct 11 ms 5712 KB Output is correct
40 Correct 64 ms 5840 KB Output is correct
41 Correct 26 ms 5844 KB Output is correct
42 Correct 32 ms 5840 KB Output is correct
43 Correct 42 ms 5916 KB Output is correct
44 Correct 39 ms 5848 KB Output is correct
45 Correct 27 ms 5856 KB Output is correct
46 Correct 7 ms 5784 KB Output is correct
47 Correct 31 ms 6068 KB Output is correct
48 Correct 147 ms 5968 KB Output is correct
49 Correct 3 ms 5776 KB Output is correct
50 Correct 67 ms 5928 KB Output is correct
51 Correct 76 ms 6040 KB Output is correct
52 Correct 18 ms 5840 KB Output is correct
53 Correct 4 ms 5804 KB Output is correct
54 Correct 19 ms 5840 KB Output is correct
55 Correct 48 ms 5812 KB Output is correct
56 Correct 59 ms 5920 KB Output is correct
57 Correct 125 ms 6020 KB Output is correct
58 Correct 156 ms 6016 KB Output is correct
59 Correct 46 ms 5856 KB Output is correct
60 Correct 70 ms 5908 KB Output is correct
61 Correct 4 ms 5796 KB Output is correct
62 Correct 3 ms 5656 KB Output is correct
63 Correct 4 ms 5792 KB Output is correct
64 Correct 5 ms 5792 KB Output is correct
65 Correct 3 ms 5796 KB Output is correct
66 Correct 3 ms 5660 KB Output is correct
67 Correct 3 ms 5792 KB Output is correct
68 Correct 4 ms 5792 KB Output is correct
69 Correct 3 ms 5660 KB Output is correct
70 Correct 4 ms 5660 KB Output is correct
71 Correct 386 ms 6144 KB Output is correct
72 Correct 14 ms 5840 KB Output is correct
73 Correct 296 ms 6100 KB Output is correct
74 Correct 240 ms 5960 KB Output is correct
75 Correct 5 ms 5804 KB Output is correct
76 Correct 160 ms 5960 KB Output is correct
77 Correct 249 ms 6144 KB Output is correct
78 Correct 13 ms 5816 KB Output is correct
79 Correct 66 ms 5864 KB Output is correct
80 Correct 179 ms 5960 KB Output is correct
81 Correct 188 ms 6076 KB Output is correct
82 Correct 186 ms 6052 KB Output is correct
83 Correct 6 ms 5712 KB Output is correct
84 Correct 84 ms 5840 KB Output is correct
85 Correct 166 ms 5960 KB Output is correct
86 Correct 29 ms 5840 KB Output is correct
87 Correct 8 ms 5800 KB Output is correct
88 Correct 20 ms 5840 KB Output is correct
89 Correct 14 ms 5800 KB Output is correct
90 Correct 5 ms 5712 KB Output is correct
91 Correct 10 ms 5796 KB Output is correct
92 Correct 4 ms 5712 KB Output is correct
93 Correct 9 ms 5712 KB Output is correct
94 Correct 15 ms 5824 KB Output is correct
95 Correct 10 ms 5840 KB Output is correct
96 Correct 7 ms 5712 KB Output is correct
97 Correct 4 ms 5712 KB Output is correct