Submission #414944

#TimeUsernameProblemLanguageResultExecution timeMemory
414944cfalasMechanical Doll (IOI18_doll)C++14
0 / 100
25 ms11624 KiB
#include "doll.h" #include<bits/stdc++.h> using namespace std; #define mp make_pair #define INF 10000000 #define MOD 1000000007 #define MID ((l+r)/2) #define HASHMOD 2305843009213693951 #define ll long long #define ull unsigned long long #define F first #define S second typedef pair<ll, ll> ii; typedef pair<ii, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef map<int, int> mii; #define EPS 1e-6 #define FOR(i,n) for(int i=0;i<((int)(n));i++) #define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++) #define FOA(v, a) for(auto v : a) int s=0, n; int cnt[1000000]; vector<vi> nxt; vector<int> C, X, Y; int b; int inv(int x){ vi a; //cout<<x<<" "; FOR(i,b) a.push_back(x%2), x/=2; ll ans=0; FOA(v,a) ans*=2, ans+=v; //cout<<ans<<endl; return ans; } void rec(int x, int l, int r){ //cout<<x<<": "<<l<<" "<<r<<endl; if(l==r) return; if(r==l+1){ if(inv(l)<(int)nxt[x].size()-1) X.push_back(nxt[x][inv(l)]); else if(l==(1<<b)-1) X.push_back(nxt[x].back()); else X.push_back(C[x]); l++; if(inv(l)<(int)nxt[x].size()-1) Y.push_back(nxt[x][inv(l)]); else if(l==(1<<b)-1) Y.push_back(nxt[x].back()); else Y.push_back(C[x]); } else{ X.push_back(-(++s)); Y.push_back(-(++s)); rec(x, l, MID); rec(x, MID+1,r); } } void create_circuit(int M, std::vector<int> A) { n = A.size(); FOR(i,n+1) cnt[i] = 0; nxt.assign(M+1, vi()); C.assign(M+1, 0); nxt[0].push_back(A[0]); FORi(i,1,n) nxt[A[i-1]].push_back(A[i]); nxt[A[n-1]].push_back(0); FOR(x,M+1){ int q = nxt[x].size(); if(q==1) C[x] = nxt[x][0]; else{ int t = q-1; int l=0; while(t) l++, t/=2; b = l; //cout<<q<<": "<<b<<endl; C[x] = -(++s); rec(x, 0, (1<<l)-1); } } #ifdef LOCAL FOA(v,C) cout<<v<<" "; cout<<endl; FOA(v,X) cout<<v<<" "; cout<<endl; FOA(v,Y) cout<<v<<" "; cout<<endl; #endif answer(C, X, Y); }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...