Submission #191767

#TimeUsernameProblemLanguageResultExecution timeMemory
191767FieryPhoenixUnscrambling a Messy Bug (IOI16_messy)C++11
100 / 100
10 ms632 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <cstdio> #include <map> #include <queue> #include <set> #include <iomanip> #include <deque> #include <cassert> #include <ctime> #include <cstring> #include <cstdlib> #include <chrono> #include <ctime> #include <random> #include <stack> #include <unordered_set> #include <unordered_map> #include <iterator> #include <climits> #include "messy.h" using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; typedef long double ld; #define INF 2001001001 #define MOD 1000000007 int ans[100001]; int N; bool contains(int x, vector<int>v){ for (int y:v) if (y==x) return true; return false; } void ask(int l, int r){ if (l>=r) return; for (int i=l;i<=(l+r)/2;i++){ string s=""; for (int j=0;j<N;j++) if (j<l || j>r) s+='1'; else if (j==i) s+='1'; else s+='0'; add_element(s); } ask(l,(l+r)/2); ask((l+r)/2+1,r); } void solve(int l, int r, vector<int>v){ string base=""; for (int i=0;i<N;i++) base+='1'; for (int x:v) base[x]='0'; vector<int>v2,v3; for (int i=l;i<=r;i++){ string s=base; s[v[i-l]]='1'; bool b=check_element(s); if (b) v2.push_back(v[i-l]); } for (int i=l;i<=r;i++) if (!contains(v[i-l],v2)) v3.push_back(v[i-l]); if (l+1==r){ ans[v2[0]]=l; ans[v3[0]]=r; return; } solve(l,(l+r)/2,v2); solve((l+r)/2+1,r,v3); } vector<int> restore_permutation(int n, int w, int r){ N=n; ask(0,n-1); compile_set(); vector<int>v; for (int i=0;i<n;i++) v.push_back(i); solve(0,n-1,v); vector<int>ret; for (int i=0;i<n;i++) ret.push_back(ans[i]); return ret; }
#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...