Submission #250094

#TimeUsernameProblemLanguageResultExecution timeMemory
250094dantoh000Minerals (JOI19_minerals)C++14
80 / 100
49 ms2704 KiB
#include <bits/stdc++.h> #include "minerals.h" using namespace std; vector<int> Q; vector<int> P; int ans[86005]; void solve(vector<int> p, int l, int r, int flag1, int flag2){ if (r == l){ //printf("%d -> %d\n",Q[l],p[0]); ans[Q[l]] = p[0]; return; } #ifdef debug printf("new %d %d\n",flag1,flag2); for (auto x : p){ printf("%d ",x); } printf("<- P\n"); for (int i = l; i <= r; i++){ printf("%d ",Q[i]); } printf("<- Q\n"); #endif //assert(p.size() == r-l+1); vector<int> Lp; vector<int> Rp; int n = r-l+1; int mid = (l+r)/2; int last; if (flag2){ for (int i = mid+1; i <= r; i++){ #ifdef debug printf("solve: removing %d\n",Q[i]); #endif last = Query(Q[i]); } } else{ for (int i = l; i <= mid; i++){ #ifdef debug printf("solve: adding %d\n",Q[i]); #endif last = Query(Q[i]); } } if (flag1){ for (int i = 0; i < n; i++){ #ifdef debug printf("solve: removing %d\n",p[i]); #endif int q = Query(p[i]); if (q == last){ Lp.push_back(p[i]); } else{ Rp.push_back(p[i]); } last = q; } } else{ for (int i = 0; i < n; i++){ #ifdef debug printf("solve: adding %d\n",p[i]); #endif int q = Query(p[i]); if (q == last){ Lp.push_back(p[i]); } else{ Rp.push_back(p[i]); } last = q; } } solve(Lp, l, mid, 1^flag1, 1); solve(Rp, mid+1, r, 1^flag1, 0); } void Solve(int N) { int last = 0; for (int i = 1; i <= 2*N; i++){ int q = Query(i); if (q == last){ Q.push_back(i); } else{ P.push_back(i); } last = q; } solve(P,0,N-1,1,1); for (auto x: Q){ Answer(x,ans[x]); } }

Compilation message (stderr)

minerals.cpp: In function 'void solve(std::vector<int>, int, int, int, int)':
minerals.cpp:52:13: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
             if (q == last){
             ^~
#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...