Submission #650051

#TimeUsernameProblemLanguageResultExecution timeMemory
650051esomerUnscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
4 ms596 KiB
#include <bits/stdc++.h> #include "messy.h" using namespace std; #define ll long long //#define endl "\n" const int MOD = 998244353; void add_lg(int n, int lg){ string s = ""; for(int i = 0; i < n; i++) s += '0'; s[0] = '1'; s[1] = '1'; add_element(s); s[1] = '0'; s[2] = '1'; s[3] = '1'; add_element(s); s[1] = '1'; s[2] = '0'; s[3] = '0'; for(int i = 2; i < lg; i++){ s[i] = '1'; add_element(s); } } void check_lg(int n, int lg, vector<int>& possible, vector<int>& ind){ string s = ""; for(int i = 0; i < n; i++) s += '0'; pair<int, int> initial = {-1, -1}; for(int i = 0; i < lg && initial.first == -1; i++){ for(int j = i + 1; j < lg && initial.first == -1; j++){ for(int q = 0; q < lg; q++) s[possible[q]] = '0'; s[possible[i]] = '1'; s[possible[j]] = '1'; //cout << "S: "<< s << endl; bool rep = check_element(s); if(rep){ initial = {possible[i], possible[j]}; } } } for(int i = 2; i < lg; i++){ for(int j = 0; j < lg; j++){ for(int q = 0; q < lg; q++) s[possible[q]] = '0'; for(int q = i - 1; q >= 2; q--) s[ind[q]] = '1'; s[initial.first] = '1'; s[initial.second] = '1'; if(s[possible[j]] == '1') continue; else if(i == lg - 1){ for(int x : possible){ if(s[x] == '0') ind[i] = x; } break; } s[possible[j]] = '1'; bool rep = check_element(s); if(rep){ ind[i] = possible[j]; break; } } } for(int q = 0; q < lg; q++) s[possible[q]] = '0'; s[initial.first] = '1'; s[ind[2]] = '1'; s[ind[3]] = '1'; bool rep = check_element(s); if(rep) {ind[0] = initial.first; ind[1] = initial.second;} else {ind[1] = initial.first; ind[0] = initial.second;} } vector<int> restore_permutation(int n, int w, int r){ if(n == 8){ string s = ""; for(int i = 0; i < n; i++) s += '0'; for(int i = 0; i < n; i++){ s[i] = '1'; add_element(s); } compile_set(); vector<int> ans(n, -1); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(ans[j] != -1) continue; s = ""; for(int q = 0; q < n; q++){ if(ans[q] != -1) s += '1'; else s += '0'; } s[j] = '1'; bool rep = check_element(s); if(rep){ ans[j] = i; break; } } } return ans; } int lg = 0; int curr = 1; while(curr < n){ lg++; curr *= 2; } vector<vector<int>> v(n, vector<int>(lg, -1)); int num = n / 2; int d = 4; map<vector<int>, int> should; for(int k = 0; k < lg; k++){ int have = 1; curr = 0; for(int i = 0; i < n; i++){ if(curr == num) {curr = 0; have = 1 - have;} if(i < lg){curr++; continue;} if(have == 1) should[v[i]]++; v[i][k] = have; curr++; } num = n / d; d *= 2; } for(int i = lg; i < n; i++){ string s = ""; for(int j = 0; j < n; j++) s += '0'; s[i] = '1'; add_element(s); for(int j = 0; j < lg; j++){ if(v[i][j]) s[j] = '1'; if(v[i][j]) add_element(s); } } add_lg(n, lg); compile_set(); vector<vector<int>> reconstruct(n, vector<int>(lg, -1)); vector<int> ind(lg); vector<int> possible; vector<bool> possible1(n, 0); for(int i = 0; i < n; i++){ string s = ""; for(int j = 0; j < n; j++) s += '0'; s[i] = '1'; bool rep = check_element(s); if(!rep) {possible.push_back(i); possible1[i] = 1;} } check_lg(n, lg, possible, ind); map<vector<int>, int> have; for(int k = 0; k < lg; k++){ map<vector<int>, int> ones; map<vector<int>, int> asked; for(int i = 0; i < n; i++){ if(possible1[i]) continue; if(asked[reconstruct[i]] + 1 == have[reconstruct[i]] && k > 0){ if(ones[reconstruct[i]] != should[reconstruct[i]]) reconstruct[i][k] = 1; else reconstruct[i][k] = 0; continue; } string s = ""; for(int j = 0; j < n; j++) s += '0'; s[i] = '1'; for(int j = 0; j < k; j++){ if(reconstruct[i][j] == 1) s[ind[j]] = '1'; } s[ind[k]] = '1'; asked[reconstruct[i]]++; bool rep = check_element(s); if(rep) {ones[reconstruct[i]]++; reconstruct[i][k] = 1;} else reconstruct[i][k] = 0; } have.clear(); ones.clear(); asked.clear(); for(int i = 0; i < n; i++){ have[reconstruct[i]]++; } } vector<int> ans(n); for(int i = 0; i < n; i++){ if(possible1[i]){ for(int j = 0; j < lg; j++){ if(ind[j] == i) ans[i] = j; } }else{ for(int j = 0; j < n; j++){ if(reconstruct[i] == v[j]) ans[i] = j; } } } 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...