제출 #1121762

#제출 시각아이디문제언어결과실행 시간메모리
1121762HasanV11010238Unscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
2 ms768 KiB
#include <vector> #include <iostream> using namespace std; #include "messy.h" void build(int l, int r, string s){ if (l == r){ return; } int mid = (l + r) / 2; string s1 = s, s2 = s; for (int i = l; i <= mid; i++){ s[i] = '1'; add_element(s); s[i] = '0'; } for (int i = l; i <= mid; i++){ s1[i] = '1'; } for (int i = mid + 1; i <= r; i++){ s2[i] = '1'; } build(l, mid, s2); build(mid + 1, r, s1); } vector<int> ans; int N, cnt = 0; void find(int l, int r, string s){ if (l == r){ for (int i = 0; i < N; i++){ if (s[i] == '0'){ ans[i] = l; return; } } return; } int mid = (l + r) / 2; string s1 = s, s2 = s; vector<int> le(N + 1, 0); for (int i = 0; i < N; i++){ if (s[i] == '0'){ s[i] = '1'; int ask = check_element(s); if (ask == 1){ le[i] = 1; } s[i] = '0'; } } for (int i = 0; i < N; i++){ if (s[i] == '0'){ if (le[i] == 1){ s1[i] = '1'; } else{ s2[i] = '1'; } } } find(l, mid, s2); find(mid + 1, r, s1); } vector<int> restore_permutation(int n, int w, int r) { N = n; ans.assign(n, 0); string s = ""; for (int i = 0; i < n; i++) s += "0"; build(0, n - 1, s); compile_set(); for (int i = 0 ; i < n; i++) s[i] = '0'; find(0, n - 1, s); return ans; }
#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...