Submission #1054636

#TimeUsernameProblemLanguageResultExecution timeMemory
1054636thieunguyenhuyUnscrambling a Messy Bug (IOI16_messy)C++17
20 / 100
1 ms604 KiB
#ifndef hwe #include "messy.h" #endif #include <bits/stdc++.h> using namespace std; #define popcount(n) (__builtin_popcountll((n))) #define clz(n) (__builtin_clzll((n))) #define ctz(n) (__builtin_ctzll((n))) #define lg(n) (63 - __builtin_clzll((n))) #define BIT(n, i) (((n) >> (i)) & 1ll) #define MASK(i) (1ll << (i)) #define FLIP(n, i) ((n) ^ (1ll << (i))) #define ON(n, i) ((n) | MASK(i)) #define OFF(n, i) ((n) & ~MASK(i)) #define Int __int128 #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long long, int> pli; typedef pair<int, long long> pil; typedef vector<pair<int, int>> vii; typedef vector<pair<long long, long long>> vll; typedef vector<pair<long long, int>> vli; typedef vector<pair<int, long long>> vil; template <class T1, class T2> bool maximize(T1 &x, T2 y) { if (x < y) { x = y; return true; } return false; } template <class T1, class T2> bool minimize(T1 &x, T2 y) { if (x > y) { x = y; return true; } return false; } template <class T> void remove_duplicate(vector<T> &ve) { sort (ve.begin(), ve.end()); ve.resize(unique(ve.begin(), ve.end()) - ve.begin()); } mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); template <class T> T random(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } template <class T> T random(T r) { return rng() % r; } const int N = 1e6 + 5; const int MOD = 1e9 + 7; const int inf = 1e9; const ll INF = 1e18; int n; vector<int> ans, p; set<string> S; #ifdef hwe void add_element(string a) { cerr << "Add: " << a << '\n'; S.emplace(a); } void compile_set() { set<string> new_set; for (auto num : S) { string new_num(num.size(), '0'); for (int i = 0; i < n; ++i) new_num[i] = num[p[i]]; new_set.emplace(new_num); } S = new_set; } bool check_element(string x) { cerr << "Check: " << x << '\n'; return S.find(x) != S.end(); } #endif void add(int l, int r, string s) { int mid = l + r >> 1; for (int i = l; i <= mid; ++i) { s[i] = '1'; add_element(s); s[i] = '0'; } if (l == r) return; string le = s, ri = s; for (int i = mid + 1; i <= r; ++i) le[i] = '1'; for (int i = l; i <= mid; ++i) ri[i] = '1'; add(l, mid, le); add(mid + 1, r, ri); } void check(int l, int r, string s) { if (l == r) { int before = ans.size(); for (int i = 0; i < s.size(); ++i) { if (s[i] == '0') ans.emplace_back(i); } return; } int mid = l + r >> 1; string le = s, ri = s; for (int i = 0; i < s.size(); ++i) { if (s[i] == '1') continue; s[i] = '1'; bool flag = check_element(s); s[i] = '0'; if (flag) le[i] = '0', ri[i] = '1'; else le[i] = '1', ri[i] = '0'; } check(l, mid, le); check(mid + 1, r, ri); } vector<int> restore_permutation(int n, int w, int r) { ans.clear(); ans.reserve(n); add(0, n - 1, string(n, '0')); compile_set(); check(0, n - 1, string(n, '0')); return ans; } #ifdef hwe signed main() { cin >> n; p.resize(n); for (auto &x : p) cin >> x; vector<int> perm = restore_permutation(n, 0, 0); for (auto &x : perm) cerr << x << ' '; cerr << '\n'; return 0; } #endif

Compilation message (stderr)

messy.cpp: In function 'void add(int, int, std::string)':
messy.cpp:95:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   95 |  int mid = l + r >> 1;
      |            ~~^~~
messy.cpp: In function 'void check(int, int, std::string)':
messy.cpp:114:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |   for (int i = 0; i < s.size(); ++i) {
      |                   ~~^~~~~~~~~~
messy.cpp:113:7: warning: unused variable 'before' [-Wunused-variable]
  113 |   int before = ans.size();
      |       ^~~~~~
messy.cpp:120:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  120 |  int mid = l + r >> 1;
      |            ~~^~~
messy.cpp:123:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |  for (int i = 0; i < s.size(); ++i) {
      |                  ~~^~~~~~~~~~
#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...