제출 #1002117

#제출 시각아이디문제언어결과실행 시간메모리
1002117c2zi6Unscrambling a Messy Bug (IOI16_messy)C++14
100 / 100
1 ms632 KiB
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(a) (a).begin(), (a).end() #define replr(i, a, b) for (int i = int(a); i <= int(b); ++i) #define reprl(i, a, b) for (int i = int(a); i >= int(b); --i) #define rep(i, n) for (int i = 0; i < int(n); ++i) #define mkp(a, b) make_pair(a, b) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VPI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<VPI> VVPI; typedef pair<ll, ll> PLL; typedef vector<ll> VL; typedef vector<PLL> VPL; typedef vector<VL> VVL; typedef vector<VVL> VVVL; typedef vector<VPL> VVPL; template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;} template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;} #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<class T> using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #include "messy.h" string inv(string s) { if (s == "W") return s; for (char& ch : s) ch = '1' - ch + '0'; return s; } vector<string> dirs; int n; void ranges(int L, int R, string t) { if (R-L+1 == 1) return; /*cout << "RANGE: " << L+1 << " " << R+1 << endl;*/ int M = (L + R) / 2; if (t == "W") { string s(n, '1'); replr(i, L, R) s[i] = '0'; int cnt = 0; replr(i, 0, n-1) if (cnt < (R-L+1)/2 && s[i] == '0') { s[i] = '1'; add_element(s); s[i] = '0'; cnt++; } ranges(M+1, R, t); ranges(L, M, t); } else { string s = t; replr(i, 0, n-1) if (t[i] == '0') { s[i] = '1'; if (check_element(s)) { t[i] = '1'; } s[i] = '0'; } /*cout << t << endl;*/ rep(i, n) if (s[i] == '0') { if (t[i] == '1') { dirs[i].pb('L'); } else { dirs[i].pb('R'); } } ranges(M+1, R, t); rep(i, n) if (s[i] == '0') t[i] = '1' - t[i] + '0'; ranges(L, M, t); } } int getnum(string s) { int l = 0; int r = n-1; for (char ch : s) { int m = (l+r)/2; if (ch == 'L') r = m; else l = m+1; } return l; } VI restore_permutation(int N, int w, int r) {n = N; ranges(0, n-1, "W"); compile_set(); dirs = vector<string>(n); ranges(0, n-1, string(n, '0')); VI ret; for (string s : dirs) { ret.pb(getnum(s)); /*cout << getnum(s) << " "; cout << endl;*/ } return ret; }
#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...