Submission #623463

#TimeUsernameProblemLanguageResultExecution timeMemory
623463M_WUnscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
2 ms468 KiB
#include <bits/stdc++.h> #include "messy.h" using namespace std; bool pos[128][128]; // original ==> permuted int N; void process(string ask, int l, int r){ if(l == r) return; int mid = (l + r) >> 1; for(int i = l; i <= mid; i++){ ask[i] = '1'; add_element(ask); ask[i] = '0'; } for(int i = l; i <= mid; i++) ask[i] = '1'; process(ask, mid + 1, r); for(int i = l; i <= mid; i++) ask[i] = '0'; for(int i = mid + 1; i <= r; i++) ask[i] = '1'; process(ask, l, mid); } void solve(string ask, int l, int r, vector<int> v){ if(l == r) return; vector<int> ll, rr; int mid = (l + r) >> 1; for(auto x : v){ ask[x] = '1'; bool res = check_element(ask); ask[x] = '0'; for(int i = l; i <= mid; i++) pos[i][x] = res; for(int i = mid + 1; i <= r; i++) pos[i][x] = !res; if(res) ll.push_back(x); else rr.push_back(x); } for(auto x : ll) ask[x] = '1'; solve(ask, mid + 1, r, rr); for(auto x : ll) ask[x] = '0'; for(auto x : rr) ask[x] = '1'; solve(ask, l, mid, ll); } vector<int> restore_permutation(int _N, int W, int R){ N = _N; string ask; for(int i = 0; i < N; i++) ask += "0"; process(ask, 0, N - 1); compile_set(); vector<int> v; for(int i = 0; i < N; i++) v.push_back(i); solve(ask, 0, N - 1, v); vector<int> res(N); for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ if(pos[j][i]) res[i] = j; } } return 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...