제출 #292118

#제출 시각아이디문제언어결과실행 시간메모리
292118SamAnd자동 인형 (IOI18_doll)C++17
6 / 100
138 ms17200 KiB
#include "doll.h" #include <bits/stdc++.h> using namespace std; #define m_p make_pair #define fi first #define se second #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() typedef long long ll; const int N = 200005; int n, m; int z; vector<int> ans; vector<int> ansx; vector<int> ansy; bool stg0(int x) { while (x % 2 == 0) x /= 2; return x == 1; } vector<int> v[N]; int bil(int pos, int d, int x) { if ((1 << d) == sz(v[x])) { return v[x][pos]; } int u = --z; ansx.push_back(0); ansy.push_back(0); int uu = bil(pos, d + 1, x); ansx[-u - 1] = uu; /*if (u == -2) { printf("%d %d\n", ansx[-u - 1], ansy[-u - 1]); }*/ uu = bil(pos + (1 << d), d + 1, x); ansy[-u - 1] = uu; return u; } void create_circuit(int M_, std::vector<int> A) { n = sz(A); m = M_; for (int i = 0; i < n; ++i) { if (i < n - 1) v[A[i]].push_back(A[i + 1]); else v[A[i]].push_back(0); } ans.push_back(A[0]); for (int x = 1; x <= m; ++x) { if (v[x].empty()) { ans.push_back(0); continue; } else if (sz(v[x]) == 1) { ans.push_back(v[x][0]); continue; } reverse(all(v[x])); while (!stg0(sz(v[x]))) { --z; ansx.push_back(0); ansy.push_back(0); v[x].push_back(z); } reverse(all(v[x])); int u = bil(0, 0, x); for (int i = 0; i < sz(v[x]); ++i) { if (v[x][i] < 0) { ansx[-v[x][i] - 1] = v[x][i]; ansy[-v[x][i] - 1] = u; } } ans.push_back(u); } answer(ans, ansx, ansy); }
#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...