Submission #747716

#TimeUsernameProblemLanguageResultExecution timeMemory
747716_martynasUnscrambling a Messy Bug (IOI16_messy)C++11
100 / 100
2 ms496 KiB
#include <bits/stdc++.h> #include "messy.h" using namespace std; #define PB push_back using vi = vector<int>; struct Group { vi from, to; }; vi restore_permutation(int n, int w, int r) { /* add_element("0"); compile_set(); check_element("0"); */ int B = __builtin_ctz(n); for(int b = B; b >= 1; b--) { for(int i = 0; i < n; i += 1<<b) { for(int j = i; j < i+(1<<b)/2; j++) { string s(n, '1'); fill(s.begin()+i, s.begin()+i+(1<<b), '0'); s[j] = '1'; add_element(s); } } } compile_set(); vector<Group> G; { Group g; for(int i = 0; i < n; i++) g.from.PB(i), g.to.PB(i); G.PB(g); } for(int b = B; b >= 1; b--) { vector<Group> Gp; for(auto g : G) { // from should be consecutive positions vi set_bits, unset_bits; for(int i : g.to) { string s(n, '1'); for(int j : g.to) s[j] = '0'; s[i] = '1'; bool resp = check_element(s); if(resp) { set_bits.PB(i); } else { unset_bits.PB(i); } } Group gl, gr; for(int i = 0; i < g.from.size(); i++) { if(i < g.from.size()/2) { gl.from.PB(g.from[i]); gl.to.PB(set_bits[i]); } else { gr.from.PB(g.from[i]); gr.to.PB(unset_bits[i - g.from.size()/2]); } } Gp.PB(gl); Gp.PB(gr); } G = Gp; } vi ans(n); for(int i = 0; i < n; i++) { ans[G[i].to[0]] = G[i].from[0]; } return ans; } /* 4 100 100 2 1 3 0 */

Compilation message (stderr)

messy.cpp: In function 'vi restore_permutation(int, int, int)':
messy.cpp:56:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |             for(int i = 0; i < g.from.size(); i++) {
      |                            ~~^~~~~~~~~~~~~~~
messy.cpp:57:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |                 if(i < g.from.size()/2) {
      |                    ~~^~~~~~~~~~~~~~~~~
#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...