Submission #303949

#TimeUsernameProblemLanguageResultExecution timeMemory
303949rocks03Cave (IOI13_cave)C++14
100 / 100
250 ms596 KiB
#include "cave.h" #include<bits/stdc++.h> #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define ff first #define ss second #define pb push_back #define SZ(x) ((int) (x).size()) using namespace std; void answer(int S[], int D[]); int tryCombination(int S[]); pii recur(int res, int l, int r, vector<int>&v, int ans[]){ if(l == r){ if(res == -1){ ans[v[l]] ^= 1; res = tryCombination(ans); } return {v[l], res}; } int m = (l + r) / 2; for(int i = l; i <= m; i++){ ans[v[i]] ^= 1; } int res2 = tryCombination(ans); for(int i = l; i <= m; i++){ ans[v[i]] ^= 1; } if(res2 == res){ return recur(res, m+1, r, v, ans); } else if(res2 == -1 || res2 > res){ return recur(res, l, m, v, ans); } else if(res2 < res){ for(int i = l; i <= m; i++){ ans[v[i]] ^= 1; } pii p = recur(res2, l, m, v, ans); return p; } } void exploreCave(int N){ int ans[N], d[N]; memset(ans, 0, sizeof(ans)); memset(d, -1, sizeof(d)); vector<int> v(N); iota(v.begin(), v.end(), 0); while(SZ(v)){ pii p = recur(tryCombination(ans), 0, SZ(v) - 1, v, ans); if(p.ss == -1){ ans[p.ff] ^= 1; d[p.ff] = tryCombination(ans); ans[p.ff] ^= 1; } else{ d[p.ff] = p.ss; ans[p.ff] ^= 1; } v.erase(find(v.begin(), v.end(), p.ff)); } answer(ans, d); }

Compilation message (stderr)

cave.cpp: In function 'std::pair<int, int> recur(int, int, int, std::vector<int>&, int*)':
cave.cpp:42:1: warning: control reaches end of non-void function [-Wreturn-type]
   42 | }
      | ^
#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...