Submission #594841

#TimeUsernameProblemLanguageResultExecution timeMemory
594841skittles1412Unscrambling a Messy Bug (IOI16_messy)C++17
70 / 100
2 ms468 KiB
#include "bits/extc++.h" using namespace std; template <typename T> void dbgh(const T& t) { cerr << t << endl; } template <typename T, typename... U> void dbgh(const T& t, const U&... u) { cerr << t << " | "; dbgh(u...); } #ifdef DEBUG #define dbg(...) \ cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \ dbgh(__VA_ARGS__); #else #define dbg(...) #define cerr \ if (false) \ cerr #endif #define endl "\n" #define long int64_t #define sz(x) int((x).size()) void add_element(string x); bool check_element(string x); void compile_set(); vector<int> bf(int n) { mt19937 cowng(chrono::steady_clock::now().time_since_epoch().count()); for (int i = 1; i <= n; i++) { add_element(string(i, '1') + string(n - i, '0')); } compile_set(); string cur(n, '0'); vector<int> ans; for (int i = 0; i < n; i++) { vector<int> left; bool vis[n] {}; for (auto& a : ans) { vis[a] = true; } for (int j = 0; j < n; j++) { if (!vis[j]) { left.push_back(j); } } shuffle(begin(left), end(left), cowng); for (auto& a : left) { cur[a] = '1'; if (check_element(cur)) { ans.push_back(a); break; } cur[a] = '0'; } } vector<int> tmp(n); for (int i = 0; i < n; i++) { tmp[ans[i]] = i; } return tmp; } vector<int> restore_permutation(int n, int, int) { if (n <= 8) { return bf(n); } for (int i = 0; i < 8; i++) { string s(n, '1'); s[i] = '0'; add_element(s); } int acnts[8] {}; for (int i = 7; i >= 0; i--) { if (i & 1) { for (int j = i + 1; j < 8; j++) { acnts[i]++; acnts[j]++; string s(n, '1'); s[i] = s[j] = '0'; add_element(s); } } } assert(acnts[6] == acnts[7]); for (int i = 0; i < 7; i++) { for (int j = 6; j < n; j++) { if ((j >> i) & 1) { string s(n, '0'); s[j] = '1'; for (int k = 0; k < i; k++) { s[k] = '1'; } add_element(s); } } } compile_set(); vector<int> cands; for (int i = 0; i < n; i++) { string s(n, '1'); s[i] = '0'; if (check_element(s)) { cands.push_back(i); } } assert(sz(cands) == 8); int cnts[8] {}; for (int i = 0; i < 8; i++) { for (int j = 0; j < i; j++) { string s(n, '1'); s[cands[i]] = s[cands[j]] = '0'; if (check_element(s)) { cnts[i]++; cnts[j]++; } } } for (int i = 0; i < 8; i++) { cerr << cnts[i] << " \n"[i == 7]; } for (int i = 0; i < 8; i++) { cerr << acnts[i] << " \n"[i == 7]; } int arr[6]; bool vis[n] {}; vector<int> ans(n); for (int i = 0; i < 6; i++) { arr[i] = cands[find(begin(cnts), end(cnts), acnts[i]) - cnts]; vis[arr[i]] = true; ans[arr[i]] = i; dbg(i, arr[i]); } for (int i = 0; i < 7; i++) { for (int j = 0; j < n; j++) { if (vis[j]) { continue; } string s(n, '0'); for (int k = 0; k < i; k++) { s[arr[k]] = '1'; } s[j] = '1'; if (check_element(s)) { ans[j] |= 1 << i; } } } 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...