Submission #295936

#TimeUsernameProblemLanguageResultExecution timeMemory
295936erd1Unscrambling a Messy Bug (IOI16_messy)C++14
0 / 100
5 ms640 KiB
#include "messy.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define all(x) (x).begin(), (x).end() template<typename It> ostream& outIt(ostream& out, It b, It e){ for(It i = b; i != e; i++) out << (i == b?"":" ") << *i; return out; } template<typename T> ostream& operator<<(ostream& out, vector<T> v){ return outIt(out << '[', all(v)) << ']'; } vector<int> solve1(int n){ string s(n, '0'); for(int i = 0; i < n-1; i++){ s[i] = '1'; add_element(s); } compile_set(); string cur(n, '0'); vector<int> ans(n); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){ if(cur[j] == '1')continue; cur[j] = '1'; if(i == n-1 || check_element(cur)){ //cout << i << " " << j << endl; ans[j] = i; break; } cur[j] = '0'; } //for(auto i: ans)cout << i << " ";cout << endl; return ans; } void add(string& s, int i){ assert(s[i] != '1'); s[i] = '1'; cout << "add " << s << endl; add_element(s), s[i] = '0'; } bool ask(string& s, int i){ assert(s[i] != '1'); s[i] = '1'; cout << "ask " << s << endl; bool ans = check_element(s); return s[i] = '0', ans; } vector<int> solve2(int n){ string s0(n, '0'), s1(n, '0'); for(int i = 0; i < __lg(n); i++){ for(int j = 0; j < n; j++) if(j&(1<<i))add(j<<1&1<<i?s1:s0, j); fill(all(s0), '0'); fill(all(s1), '0'); for(int j = 0; j < n; j++) (j&(1<<i)?s0:s1)[j] = '1'; } compile_set(); fill(all(s0), '0'); fill(all(s1), '0'); vector<int> ans(n); for(int i = 0; i < __lg(n); i++){ for(int j = 0; j < n; j++) ans[j] |= ask(ans[j]<<1&1<<i?s1:s0, j)<<i; fill(all(s0), '0'); fill(all(s1), '0'); for(int j = 0; j < n; j++) (ans[j]&(1<<i)?s0:s1)[j] = '1'; } return ans; } vector<int> restore_permutation(int n, int w, int r) { //if(r <= n*n)return solve1(n); return solve2(n); }
#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...