Submission #300683

#TimeUsernameProblemLanguageResultExecution timeMemory
300683JPN20The Big Prize (IOI17_prize)C++17
20 / 100
118 ms3192 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; int p1[1 << 18]; int p2[1 << 18]; int maxn = 0; vector<int> V; vector<int> W; int Rand() { return (rand() % 32768) * 32768 + (rand() % 32768); } pair<int, int> query(int pos) { if (p1[pos] >= 0) return make_pair(p1[pos], p2[pos]); vector<int> vec = ask(pos); p1[pos] = vec[0]; p2[pos] = vec[1]; return make_pair(p1[pos], p2[pos]); } void dfs(int cl, int cr, int c1, int c2) { //cout << cl << " " << cr << " " << c1 << " " << c2 << endl; if (cl == cr) { W.push_back(V[cl]); return; } int cm = (cl + cr) / 2; int el = -1, e1 = 0; int er = -1, e2 = 0; for (int i = cm; i >= cl; i--) { pair<int, int> T = query(V[i]); if (T.first + T.second == maxn) { el = i; e1 = T.first; break; } else { W.push_back(V[i]); } } for (int i = cm; i <= cr; i++) { pair<int, int> T = query(V[i]); if (T.first + T.second == maxn) { er = i; e2 = T.first; break; } else { W.push_back(V[i]); } } if (el >= 0 && c1 != e1 && cl <= el + 1) dfs(cl, el - 1, c1, e1); if (er >= 0 && c2 != e2 && er + 1 <= cr) dfs(er + 1, cr, e2, c2); } vector<int> solve() { //for (int i = 0; i < V.size(); i++) cout << V[i] << " " ; cout << endl; maxn = 0; W.clear(); for (int i = 0; i < 20; i++) { int T = Rand() % V.size(); pair<int, int> T2 = query(V[T]); maxn = max(maxn, T2.first + T2.second); } //cout << maxn << endl; dfs(0, V.size() - 1, 0, maxn); return W; } int find_best(int n) { for (int i = 0; i < n; i++) p1[i] = -1; for (int i = 0; i < n; i++) p2[i] = -1; for (int i = 0; i < n; i++) V.push_back(i); while (V.size() >= 2) { vector<int> V2 = solve(); sort(V2.begin(), V2.end()); V2.erase(unique(V2.begin(), V2.end()), V2.end()); V = V2; } return V[0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...