Submission #936650

#TimeUsernameProblemLanguageResultExecution timeMemory
936650GhettoThe Big Prize (IOI17_prize)C++17
92.42 / 100
31 ms756 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; int n; int v_sum; int find_v_sum() { unordered_map<int, int> sum_freq; for (int i = 0; i < min(n, 1000); i++) { vector<int> res = ask(i); sum_freq[res[0] + res[1]]++; } for (pii sf : sum_freq) if (sf.second >= min(n / 2, 500)) return sf.first; assert(true == false); } bool is_v(int res_sum) { return res_sum == v_sum; } vector<int> append(vector<int> v1, vector<int> v2) { v1.insert(v1.end(), v2.begin(), v2.end()); return v1; } int find_one(int lo, int hi, int l, int r) { // -1 if none // cout << "CALL " << lo << " " << hi << " " << l << " " << r << endl; if (lo > hi) return -1; vector<int> res; int l_mid = (lo + hi) / 2, r_mid = (lo + hi) / 2; while (r_mid <= hi) { res = ask(r_mid); if (is_v(res[0] + res[1])) break; if (res[0] + res[1] == 0) return r_mid; r_mid++; } if (r_mid == hi + 1) return find_one(lo, l_mid - 1, l, r + r_mid - l_mid); int l_size = res[0] - l - (r_mid - l_mid); int r_size = res[1] - r; // cout << "DETAILS " << l_mid << " " << r_mid << " " << l_size << " " << r_size << endl; assert(min(l_size, r_size) >= 0); if (l_size == 0 && r_size == 0) return -1; else if (l_size == 0) return find_one(r_mid + 1, hi, l + r_mid - l_mid, r); else if (r_size == 0) return find_one(lo, l_mid - 1, l, r + r_mid - l_mid); return max(find_one(lo, l_mid - 1, l, r + r_size + r_mid - l_mid), find_one(r_mid + 1, hi, l + l_size + r_mid - l_mid, r)); } int find_best(int tmp_n) { n = tmp_n; v_sum = find_v_sum(); int ans = find_one(0, n - 1, 0, 0); assert(ans != -1); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...