제출 #213002

#제출 시각아이디문제언어결과실행 시간메모리
213002mode149256자동 인형 (IOI18_doll)C++14
6 / 100
121 ms12292 KiB
/*input */ #include <bits/stdc++.h> #include "doll.h" using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<vl> vll; typedef vector<pi> vpi; typedef vector<vpi> vpii; typedef vector<pl> vpl; typedef vector<cd> vcd; typedef vector<pd> vpd; typedef vector<bool> vb; typedef vector<vb> vbb; typedef std::string str; typedef std::vector<str> vs; #define x first #define y second #define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n" const int MOD = 1000000007; const ll INF = std::numeric_limits<ll>::max(); const int MX = 100101; const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L; template<typename T> pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); } template<typename T> pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); } template<typename T> T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); } template<typename T> T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); } template<typename T> void print(vector<T> vec, string name = "") { cout << name; for (auto u : vec) cout << u << ' '; cout << '\n'; } vi C; vi X, Y; int S = 0; vii iseina; int N; int truksta; int n; int pradSw; int maxLvl; vpi place; int nxtS() { X.emplace_back(0); Y.emplace_back(0); S++; return -S; } void make(int sw, int currLvl, int pos) { // printf("sw = %d\n", sw); int manoMedyElm = (1 << (maxLvl - currLvl + 1)); if (manoMedyElm <= truksta) { X[sw] = Y[sw] = pradSw; truksta -= manoMedyElm; return; } if (currLvl == maxLvl) { if (!truksta) place[pos] = {sw, 0}; else { X[sw] = pradSw; truksta--; } pos |= (1 << currLvl); place[pos] = {sw, 1}; } else { X[sw] = nxtS(); Y[sw] = nxtS(); make(-X[sw], currLvl + 1, pos); make(-Y[sw], currLvl + 1, pos | (1 << currLvl)); } } void daryk(int m) { int sz = iseina[m].size(); n = (1 << (int)ceil(log2(sz))); maxLvl = log2(n); maxLvl--; truksta = n - sz; // printf("sz = %d, n = %d, mxlvl = %d,truksta = %d\n", sz, n, maxLvl, truksta); place = vpi(n, pi(0, 0)); C[m] = nxtS(); pradSw = C[m]; make(-C[m], 0, 0); // printf("m = %d, sz = %d, n = %d, place:\n", m, sz, n); // for (auto u : place) // printf("%d %d\n", u.x, u.y); // printf("\n"); int j = 0; for (int i = 0; i < sz; ++i) { while (j < n and !place[j].x) j++; assert(j < n); int h = place[j].x; // printf("i = %d, iseina = %d, h = %d\n", i, iseina[m][i], h); if (place[j].y) Y[h] = iseina[m][i]; else X[h] = iseina[m][i]; j++; } } void create_circuit(int M, vi A) { N = A.size(); C = vi(M + 1); iseina = vii(M + 1); A.emplace_back(0); C[0] = A[0]; for (int i = 0; i < N; ++i) iseina[A[i]].emplace_back(A[i + 1]); X.emplace_back(0); Y.emplace_back(0); for (int i = 1; i <= M; ++i) { if (iseina[i].empty()) C[i] = 0; else if (iseina[i].size() == 1) C[i] = iseina[i][0]; else daryk(i); } X.erase(X.begin()); Y.erase(Y.begin()); // printf("S = %d\n", S); // print(C, "C: "); // for (int i = 0; i < S; ++i) printf("%d ", X[i]); printf("\n"); // for (int i = 0; i < S; ++i) printf("%d ", Y[i]); printf("\n"); 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...