제출 #1169964

#제출 시각아이디문제언어결과실행 시간메모리
1169964patgraMinerals (JOI19_minerals)C++20
40 / 100
9 ms3020 KiB
#include <bits/stdc++.h> #define rep(a,b,c) for(auto a = (b); a != (c); a++) #define repD(a,b,c) for(auto a = (b); a != (c); a--) #define repIn(a, b) for(auto& a : (b)) #define repIn2(a, b, c) for(auto& [a, b] : (c)) constexpr bool dbg = 0; #define DEBUG if constexpr(dbg) #define DC DEBUG std::cerr #define eol std::endl #define ll long long #define pb push_back using namespace std; #include "minerals.h" constexpr int maxn = 43007; bool isIn[maxn]; int cntIn; int n; int myQuery(int i) { if(isIn[i]) cntIn--; else cntIn++; isIn[i] = !isIn[i]; int ret = cntIn - Query(i + 1); DC << " ============ Querying " << i << " -> " << ret << eol; return ret; } int curPairs; void dq(vector<int> h1, vector<int> h2, bool in1, bool in2) { assert(h1.size() == h2.size()); DEBUG { DC << "D&Q\n h1: {"; repIn(i, h1) DC << i << ", "; DC << "}\n h2: {"; repIn(i, h2) DC << i << ", "; DC << "}\n in1 " << in1 << " ; in2 " << in2 << eol; repIn(i, h1) assert(isIn[i] == in1); repIn(i, h2) assert(isIn[i] == in2); } int sz = (int)h1.size(), m = sz / 2; if(sz == 1) { Answer(h1.back() + 1, h2.back() + 1); return; } if(in1) rep(i, m, sz) curPairs = myQuery(h1[i]); if(!in1) rep(i, 0, m) curPairs = myQuery(h1[i]); vector<int> lh1, lh2, rh1, rh2; rep(i, 0, m) lh1.pb(h1[i]); rep(i, m, sz) rh1.pb(h1[i]); repIn(i, h2) { auto newPairs = myQuery(i); if(newPairs != curPairs) lh2.pb(i); else rh2.pb(i); curPairs = newPairs; } dq(lh1, lh2, true, !in2); dq(rh1, rh2, false, !in2); } void Solve(int N) { n = N; vector<int> firstHalf, secondHalf; rep(i, 0, 2 * N) { if((int)firstHalf.size() == n) { secondHalf.pb(i); continue; } if((int)secondHalf.size() == n) { firstHalf.pb(i); continue; } auto newPairs = myQuery(i); if(newPairs) secondHalf.pb(i), myQuery(i); else firstHalf.pb(i); } dq(firstHalf, secondHalf, 1, 0); }
#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...