Submission #554076

#TimeUsernameProblemLanguageResultExecution timeMemory
554076keta_tsimakuridzeUnscrambling a Messy Bug (IOI16_messy)C++14
100 / 100
3 ms468 KiB
#include<bits/stdc++.h> #include "messy.h" using namespace std; vector<int> p, P; int W, R; /* map<string,int> c; void add_element(string s) { string sn = s; for(int i = 0; i < s.size(); i++) { s[i] = sn[P[i]]; } c[s]++; } bool check_element(string s) { return (c[s] > 0 ? true : false); } */ string get(string s) { string sn = ""; for(int i = 1; i < s.size(); i++) sn += s[i]; return sn; } void add(int l, int r, int n) { string s = ""; if(l == r) return; for(int i = 0; i <= n; i++) s += '0'; for(int i = 1; i < l; i++) s[i] = '1'; for(int i = r + 1; i <= n; i++) s[i] = '1'; int mid = (l + r) / 2; for(int i = l; i <= mid; i++) { for(int j = l; j <= mid; j++) { s[j] = '0'; } s[i] = '1'; W--; assert(W >= 0); add_element(get(s)); } add(l, mid, n); add(mid + 1, r, n); } void solve(int l, int r, vector<int> v, int n) { string s = ""; if(l == r) { p[v.back()] = r - 1; return; } for(int i = 0; i <= n; i++) s += '1'; vector<int> vl, vr; for(int j = 0; j < v.size(); j++) { for(int i = 0; i < v.size(); i++) s[v[i] + 1] = '0'; s[v[j] + 1] = '1'; R--; assert(R >= 0); if(check_element(get(s))) vl.push_back(v[j]); else vr.push_back(v[j]); } int mid = (l + r) / 2; solve(l, mid, vl, n); solve(mid + 1, r, vr, n); } std::vector<int> restore_permutation(int n, int w, int r) { W = w; R = r; add(1, n, n); vector<int> v; p.resize(n); compile_set(); for(int i = 0; i < n; i++) v.push_back(i); solve(1, n, v, n); return p; } /* int main() { int n, w, r; cin >> n >> w >> r; P.resize(n); for(int i = 0; i < n; i++) { cin >> P[i]; } vector<int> v = restore_permutation(n, w, r); for(int i = 0; i < v.size(); i++) cout << v[i] << " "; assert(v == P); } */

Compilation message (stderr)

messy.cpp: In function 'std::string get(std::string)':
messy.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for(int i = 1; i < s.size(); i++) sn += s[i];
      |                 ~~^~~~~~~~~~
messy.cpp: In function 'void solve(int, int, std::vector<int>, int)':
messy.cpp:52:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for(int j = 0; j < v.size(); j++) {
      |                 ~~^~~~~~~~~~
messy.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int i = 0; i < v.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...