제출 #139037

#제출 시각아이디문제언어결과실행 시간메모리
139037Mahdi_Jfri자동 인형 (IOI18_doll)C++14
84 / 100
207 ms17408 KiB
#include "doll.h" #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define bit(a , b) (((a)>>(b))&1) const int maxn = 1e6 + 20; const int maxb = 20; int id , pt; int x[maxn] , y[maxn]; vector<int> a , bits; int build(int n) { if(n == 0) return -1; int root = id++; x[root] = build(n - 1); y[root] = build(n - 1); return root; } int solve(int k , int n) { if(n == (1 << k)) return build(k); int root = id++; if(n <= (1 << (k - 1))) { x[root] = 0; y[root] = solve(k - 1 , n); } else { x[root] = build(k - 1); n -= (1 << (k - 1)); y[root] = solve(k - 1 , n); } return root; } bool is[maxn]; void dfs(int v) { while(pt < (int)a.size()) { if(!is[v]) { is[v] ^= 1; if(x[v] == -1) { x[v] = a[pt++] + maxn * 10 , v = 0; } else { v = x[v]; } } else { is[v] ^= 1; if(y[v] == -1) { y[v] = a[pt++] + maxn * 10 , v = 0; } else { v = y[v]; } } } } void create_circuit(int m, vector<int> A) { memset(x , -1 , sizeof x); memset(y , -1 , sizeof y); a = A; a.pb(0); int n = a.size(); for(int j = 0; j < 20; j++) if(bit(n , j)) bits.pb(j); solve(bits.back() + 1 , n); dfs(0); for(int i = 0; i < id; i++) { int v = i; if(x[v] >= maxn * 10) x[v] = x[v] - maxn * 10; else x[v] = -x[v] - 1; if(y[v] >= maxn * 10) y[v] = y[v] - maxn * 10; else y[v] = -y[v] - 1; } vector<int> res; for(int i = 0; i <= m; i++) res.pb(-1); vector<int> X , Y; for(int i = 0; i < id; i++) X.pb(x[i]) , Y.pb(y[i]); answer(res , 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...