제출 #247707

#제출 시각아이디문제언어결과실행 시간메모리
247707LittleFlowers__Unscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
3 ms512 KiB
#include <bits/stdc++.h> using namespace std; #define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;}) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int l,int r){return l+rng()%(r-l+1);} #define fasty ios_base::sync_with_stdio(0),cin.tie(0); #define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a) #define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a) #define forv(a,b) for(auto&a:b) #define fi first #define se second #define pb push_back #define ii pair<int,int> #define mt make_tuple #define all(a) a.begin(),a.end() #define reset(f, x) memset(f, x, sizeof(f)) #define gg exit(0); #include "messy.h" void dfs(int l,int r,int n){ if(l==r) return; string s; forinc(i,1,n) s.pb(l>i||i>r?'1':'0'); int m=(l+r)/2; forinc(i,l,m){ s[i-1]='1'; add_element(s); s[i-1]='0'; } dfs(l,m,n); dfs(m+1,r,n); } vector<int> ans; void dfs(int n,int l,int r,string s){ n=s.size(); if(l==r) return; vector<int> lf,rt; forinc(i,1,n) if(s[i-1]=='0'){ s[i-1]='1'; if(check_element(s)) lf.pb(i); else rt.pb(i); s[i-1]='0'; } if(lf.size()==1){ ans[lf[0]-1]=l-1; ans[rt[0]-1]=r-1; } int m=(l+r)/2; forv(i,lf) s[i-1]='1'; dfs(n/2,m+1,r,s); forv(i,lf) s[i-1]='0'; forv(i,rt) s[i-1]='1'; dfs(n/2,l,m,s); } vector<int> restore_permutation(int n,int w,int r){ dfs(1,n,n); compile_set(); string s; forinc(i,1,n) s.pb('0'); ans.resize(n); dfs(n,1,n,s); return ans; }
#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...