Submission #399062

#TimeUsernameProblemLanguageResultExecution timeMemory
399062galcaThe Collection Game (BOI21_swaps)C++14
100 / 100
7 ms324 KiB
#include "swaps.h" //#include <vector> using namespace std; void solve(int N, int V) { int n = N; while (n & (n - 1)) { n++; } vector<int> res(n); for (int i=0; i<n; i++) { res[i] = i+1; } for (int k = 2; k < (N + N - 1); k *= 2) { for (int j = k/2; j > 0; j /= 2) { for (int i = 0; i < n; i++) { int ip = i ^ j; if (ip > i) { int room1, room2; if ((i ^ k) < i) { // expecting room at ip to be > room at i room1 = res[ip]; room2 = res[i]; } else { // expecting room at i to be > room at ip room1 = res[i]; room2 = res[ip]; } // if expected max is out of bound, swap // if expected min is out of bound, don't call if (room1 > N) { int tmp = res[i]; res[i] = res[ip]; res[ip] = tmp; } else { if (room2 <= N) { schedule(room1, room2); } } } } vector<int> v = visit(); int idx = 0; for (int i = 0; i < n; i++) { int ip = i ^ j; int room1 = res[i]; int room2 = res[ip]; if ((ip > i) && (room1 <= N) && (room2 <= N)) { if (v[idx++] == 0) { int tmp = res[i]; res[i] = res[ip]; res[ip] = tmp; } } } } } if (N < n) { vector<int> resf(N); for (int i = 0; i < N; i++) { resf[i] = res[i]; } answer(resf); } else { answer(res); } }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...