Submission #796791

#TimeUsernameProblemLanguageResultExecution timeMemory
796791SlavicGMinerals (JOI19_minerals)C++17
100 / 100
58 ms6428 KiB
#include <bits/stdc++.h> #include "minerals.h" using namespace std; #define sz(a) (int)a.size() mt19937 rng(69); //b - valoarea elementului, stateul (aprins/stins) int ans = 0, prevans = -1; const int N = 1e5 + 69; int in[N], added[N]; map<pair<int, int>, int> cant_be; void rec(vector<int> a, vector<pair<int, int>> b, int offset) { if(b.empty() || a.empty()) return; if(sz(b) == 1) { for(auto x: a) Answer(x, b[0].first); return; } vector<int> first_half, second_half; int mid = (sz(b) < 10 ? sz(b) / 2 : min(sz(b) - 1, (int)(sz(b) * 0.369))); vector<pair<int, int>> left, right; for(auto& x: a) { if(added[x]) continue; if(in[x] <= mid + offset) { first_half.push_back(x); x = -1; } else added[x] = 1; } for(int i = 0; i < sz(b); ++i) { if(i < mid) left.push_back(b[i]); else right.push_back(b[i]); } int offset2 = offset + sz(left); { int change1 = 0, change2 = 0; for(auto& x: left) { if(!x.second) { ++change1; } else { ++change2; } } for(auto& x: right) { if(x.second) { ++change1; } else { ++change2; } } if(change2 < change1) swap(left, right), swap(first_half, second_half), swap(offset, offset2); } for(auto& x: left) { if(!x.second) { prevans = Query(x.first); x.second = 1; } } for(auto& x: right) { if(x.second) { prevans = Query(x.first); x.second = 0; } } shuffle(a.begin(), a.end(), rng); for(auto x: a) { if(x == -1) continue; if(sz(second_half) >= sz(right)) { first_half.push_back(x); continue; } if(sz(first_half) >= sz(left)) { second_half.push_back(x); continue; } int ans = Query(x); if(ans == prevans) { first_half.push_back(x); } else { second_half.push_back(x); } prevans = ans; } rec(second_half, right, offset2); rec(first_half, left, offset); } void Solve(int n) { for(int i = 0; i < N; ++i) in[i] = INT_MAX; vector<int> p1, p2; vector<int> bulanea(2 * n); iota(bulanea.begin(), bulanea.end(), 1); shuffle(bulanea.begin(), bulanea.end(), rng); for(int i: bulanea) { ans = Query(i); if(ans == prevans) { p2.push_back(i); in[i] = ans; } else { p1.push_back(i); } prevans = ans; if(sz(p1) == n) { for(int j = 0; j < sz(bulanea); ++j) { if(bulanea[j] == i) { for(int f = j + 1; f < sz(bulanea); ++f) { p2.push_back(bulanea[f]); } break; } } break; } } assert(sz(p1) == n && sz(p2) == n); vector<pair<int, int>> b; for(auto x: p1) b.push_back({x, 1}); rec(p2, b, 0); } /* 4 1 5 2 6 3 4 7 8 */ // g++ -Wall -lm -static -DEVAL -o minerals -O2 minerals.cpp grader.cpp -std=c++17
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...