제출 #249955

#제출 시각아이디문제언어결과실행 시간메모리
249955ernestvw자동 인형 (IOI18_doll)C++11
6 / 100
131 ms12544 KiB
#include <bits/stdc++.h> using namespace std; #define sz(x) ((int)x.size()) void answer(vector<int> C, vector<int> X, vector<int> Y); int n, m; vector<int> a; vector<vector<int>> adj; int p = 0; vector<int> c, x, y; int new_switch(int g, int d) { p++; x.push_back(g); y.push_back(d); return -p; } int new_switch(int g) { p++; x.push_back(-p); y.push_back(g); return -p; } vector<int> ordre; vector<int> invordre; vector<int> liste; int PR = 1; int mom = -1; void recurse(int x, int pr) { if(pr == PR) { ordre.push_back(x); return; } recurse(x, 2 * pr); recurse(x + pr, 2 * pr); } int build(int x, int pr) { if(pr == 1) { mom = new_switch(build(x, 2 * pr), build(x + pr, 2 * pr)); return mom; } if(pr == PR) return (liste[x] == -1 ? mom : liste[x]); return new_switch(build(x, 2 * pr), build(x + pr, 2 * pr)); } int create(int t) { if(sz(adj[t]) == 0) return 0; int pr = 1; while(pr < sz(adj[t])) pr *= 2; if(pr == 1) return adj[t][0]; PR = pr; ordre.clear(); recurse(0, 1); invordre.resize(pr); for(int i = 0; i < sz(ordre); ++i) invordre[ordre[i]] = i; liste.assign(pr, -1); for(int i = 0; i < pr - sz(adj[t]); ++i) liste[invordre[i]] = -1; for(int i = pr - sz(adj[t]); i < pr; ++i) liste[invordre[i]] = adj[t][i - pr + sz(adj[t])]; return build(0, 1); } /*int Create(int t, int i, int j) { if(i > j) return 0; if(i == j) return adj[t][i]; if(i + 2 == j) { int p1 = new_switch(adj[t][i], adj[t][i + 1]); int p2 = new_switch(-p-2, adj[t][i + 2]); return new_switch(p1, p2); } if(i + 3 == j) return new_switch(new_switch(adj[t][i], adj[t][i + 2]), new_switch(adj[t][i + 1], adj[t][i + 3])); return new_switch(create(t, i, (i + j) / 2), create(t, (i + j) / 2 + 1, j)); }*/ void create_circuit(int M, vector<int> A) { n = (int)A.size(); m = M; a = A; c.assign(m + 1, 0); adj.assign(m + 1, vector<int>()); for(int i = 0; i < n - 1; ++i) adj[a[i]].push_back(a[i + 1]); adj[0].push_back(a[0]); adj[a.back()].push_back(0); /* for(int i = 0; i <= m; ++i) { cout << i << ": "; for(int j : adj[i])cout<<j<<" "; cout<<endl; } */ for(int i = 0; i <= m; ++i) c[i] = create(i); 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...