제출 #481378

#제출 시각아이디문제언어결과실행 시간메모리
481378HamletPetrosyanUnscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
2 ms488 KiB
#include <bits/stdc++.h> using namespace std; #include "messy.h" int n, w, r; vector<int> res; void add_all_elements(int l, int r){ if(l == r) return; string s(n, '1'); for(int i = l; i <= r; i++) { s[i] = '0'; } int mid = (l + r) / 2; for(int i = l; i <= mid; i++){ s[i] = '1'; add_element(s); s[i] = '0'; } add_all_elements(l, mid); add_all_elements(mid + 1, r); } void get_positions(int l, int r, string s){ // cout << l << " " << r << " - " << s << endl; string now = s; if(l == r - 1){ bool doit = false; for(int i = 0; i < n; i++){ if(s[i] == '0'){ if(doit){ now[i] = '1'; break; } s[i] = '1'; if(check_element(s)){ now[i] = '1'; s[i] = '0'; break; } else { doit = true; } s[i] = '0'; } } for(int i = 0; i < n; i++){ if(now[i] != s[i]){ res[i] = l; } if(now[i] == '0'){ res[i] = r; } } // cout << l << " " << r << " " << res[l] << " " << res[r] << endl; return; } for(int i = 0; i < n; i++){ if(s[i] == '0'){ s[i] = '1'; if(check_element(s)){ now[i] = '1'; } s[i] = '0'; } } // cout << s << " | " << now << endl; int mid = (l + r) / 2; get_positions(mid + 1, r, now); for(int i = 0; i < n; i++){ if(s[i] != now[i]){ now[i] = '0'; } else { now[i] = '1'; } } get_positions(l, mid, now); } vector<int> restore_permutation(int N, int W, int R) { n = N, w = W, r = R; res = vector<int>(n, 0); add_all_elements(0, n - 1); compile_set(); get_positions(0, n - 1, string(n, '0')); 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...