제출 #421140

#제출 시각아이디문제언어결과실행 시간메모리
421140dxz05Unscrambling a Messy Bug (IOI16_messy)C++14
100 / 100
2 ms460 KiB
#include <bits/stdc++.h> #include "messy.h" using namespace std; const int MAXN = 512; int n; int p[MAXN], q[MAXN]; void add(int l, int r){ if (l == r) return; int m = (l + r) >> 1; string s(n, '1'); for (int i = l; i <= r; i++) s[i] = '0'; for (int i = l; i <= m; i++) { s[i] = '1'; add_element(s); //cout << s << endl; s[i] = '0'; } add(l, m); add(m + 1, r); } vector<int> combine(vector<int> a, vector<int> b){ for (int x : b) a.push_back(x); return a; } void build(int l, int r, vector<int> v){ //cout << l << ' ' << r << "\t"; for (int x : v) cout << x << ' '; cout << endl; if (l == r){ p[v[0]] = l; q[l] = v[0]; return; } vector<int> lf, rg; string s(n, '1'); for (int i : v) s[i] = '0'; for (int i : v){ s[i] = '1'; // cout << s << endl; if (check_element(s)){ lf.push_back(i); } else rg.push_back(i); s[i] = '0'; } int m = (l + r) >> 1; build(l, m, lf); build(m + 1, r, rg); } vector<int> restore_permutation(int _n, int w, int r) { n = _n; add(0, n - 1); compile_set(); //cout << endl; vector<int> v(n); for (int i = 0; i < n; i++) v[i] = i; build(0, n - 1, v); vector<int> ret(n); for (int i = 0; i < n; i++) ret[i] = p[i]; return ret; } /* 8 256 256 0 1 5 3 4 2 6 7 */
#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...