제출 #727656

#제출 시각아이디문제언어결과실행 시간메모리
727656jwvg0425커다란 상품 (IOI17_prize)C++17
20 / 100
108 ms1104 KiB
#include <stdio.h> #include <vector> #include <queue> #include <algorithm> #include <iostream> #include <string> #include <bitset> #include <map> #include <set> #include <tuple> #include <string.h> #include <math.h> #include <random> #include <functional> #include <assert.h> #include <math.h> #include "prize.h" #define all(x) (x).begin(), (x).end() #define xx first #define yy second using namespace std; template<typename T, typename Pr = less<T>> using pq = priority_queue<T, vector<T>, Pr>; using i64 = long long int; using ii = pair<int, int>; using ii64 = pair<i64, i64>; vector<ii> finded; int bigSize; int cnt(int l, int r) { return upper_bound(all(finded), ii{ r, 1 << 30 }) - lower_bound(all(finded), ii{ l, -1 }); } void test(int n, int l, int r) { if (l > r) return; int m = (l + r) / 2; int ml = m; int mlL = 0, mlR = 0; while (ml >= l) { if (any_of(all(finded), [ml](ii x) { return x.xx == ml; })) { ml--; continue; } auto res = ask(ml); if (res[0] + res[1] != bigSize) { finded.insert(lower_bound(all(finded), ii{ ml, res[0] + res[1] }), ii{ ml, res[0] + res[1] }); ml--; } else { mlL = res[0]; mlR = res[1]; break; } } if (ml > l && mlL != cnt(0, ml - 1)) test(n, l, ml - 1); if (m + 1 <= r && mlR - (m - ml) != cnt(m + 1, n - 1)) test(n, m + 1, r); } random_device rd; int find_best(int n) { mt19937 mt(rd()); vector<int> indexs(n); for (int i = 0; i < n; i++) indexs[i] = i; shuffle(all(indexs), mt); vector<ii> ix; for (int i = 0; i < min(n, 30); i++) { auto q = ask(indexs[i]); ix.emplace_back(q[0] + q[1], indexs[i]); } sort(all(ix)); bigSize = ix.back().xx; test(n, 0, n - 1); for (auto& [k, v] : finded) { if (v == 0) return k; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...