Submission #966694

#TimeUsernameProblemLanguageResultExecution timeMemory
966694anangoUnscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
2 ms856 KiB
#include <vector> #include <bits/stdc++.h> using namespace std; #include "messy.h" vector<int> answer; int N; vector<string> construct_strings(vector<int> index_set) { //construct all strings going from all 1s except index_set 0s with one 1 vector<char> s; vector<string> ans; for (int i=0; i<N; i++) { s.push_back('1'); } for (auto i:index_set) { s[i] = '0'; } for (auto i:index_set) { s[i] = '1'; string x(s.begin(), s.end()); //cout << l <<" " <<r << " " << i <<" " << x << endl; ans.push_back(x); s[i] = '0'; } return ans; } void solve(int l, int r, vector<int> index_set) { // cout << "call " << l << " " << r << " " << index_set.size() << endl; assert(index_set.size()==(r-l+1)); if (l==r) { assert(index_set.size()==1); answer[index_set.back()] = l; return; } int m=(l+r)/2; sort(index_set.begin(), index_set.end()); //l to m and m+1 to r vector<string> test_strings = construct_strings(index_set); vector<int> firstind; vector<int> secondind; for (int i=0; i<r-l+1; i++) { //if i is there, put it into left, otherwise into right if (check_element(test_strings[i])) { firstind.push_back(index_set[i]); } else { secondind.push_back(index_set[i]); } } // cout << "split " << l <<" " << m <<" " << r << endl; for (auto i:firstind) { // cout << i <<" "; } // cout << endl; for (auto i:secondind) { // cout << i <<" "; } // cout << endl; solve(l, m, firstind); solve(m+1, r, secondind); return; } std::vector<int> restore_permutation(int n, int w, int r) { N=n; //n=8 //10000000 //01000000 //00100000 //00010000 //from these we have 4 indices for which (0,1,2,3)->(a,b,c,d) //and the other 4 indices (4,5,6,7)->(e,f,g,h) //so now solve the problem for n=4 but putting 1 in any irrelevant bits //so for each subpower, say 2^c, for each blocked segment of that length, //replace each of that segment with 1 and the rest 0, and the rest of the bits 1, for half of such possibilities //then query all of them int b=-1; int on=n; while (on) { on/=2; b++; } answer=vector<int>(n,-1); for (int c = 1; c<=b; c++) { for (int st=0; st<n; st+=1<<c) { //insert the first half of the segment int l=st; int r=(st+(1<<c))-1; int m = (l+r)/2; vector<char> s; for (int i=0; i<l; i++) { s.push_back('1'); } for (int i=l; i<=r; i++) { s.push_back('0'); } for (int i=r+1; i<n; i++) { s.push_back('1'); } for (int i=l; i<=m; i++) { s[i] = '1'; string x(s.begin(), s.end()); // cout << l <<" " <<m <<" " << r << " " << i <<" " << x << endl; add_element(x); s[i] = '0'; } } } compile_set(); vector<int> range; for (int i=0; i<n; i++) { range.push_back(i); } solve(0, n-1, range); return answer; }

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from messy.cpp:2:
messy.cpp: In function 'void solve(int, int, std::vector<int>)':
messy.cpp:31:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     assert(index_set.size()==(r-l+1));
      |            ~~~~~~~~~~~~~~~~^~~~~~~~~
messy.cpp:53:15: warning: unused variable 'i' [-Wunused-variable]
   53 |     for (auto i:firstind) {
      |               ^
messy.cpp:57:15: warning: unused variable 'i' [-Wunused-variable]
   57 |     for (auto i:secondind) {
      |               ^
#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...