Submission #601455

#TimeUsernameProblemLanguageResultExecution timeMemory
601455skittles1412Mechanical Doll (IOI18_doll)C++17
56.57 / 100
143 ms19540 KiB
#include "bits/extc++.h" using namespace std; template <typename T> void dbgh(const T& t) { cerr << t << endl; } template <typename T, typename... U> void dbgh(const T& t, const U&... u) { cerr << t << " | "; dbgh(u...); } #ifdef DEBUG #define dbg(...) \ cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \ dbgh(__VA_ARGS__); #else #define dbg(...) #define cerr \ if (false) \ cerr #endif #define endl "\n" #define long int64_t #define sz(x) int((x).size()) void answer(vector<int> C, vector<int> X, vector<int> Y); vector<pair<int, int>> ans; pair<int, int> alloc() { int o = sz(ans), oind = -o - 1; ans.emplace_back(0, 0); return {o, oind}; } int construct(const vector<int>& arr) { if (sz(arr) == 1) { return arr[0]; } auto [o, oind] = alloc(); // auto [a, aind] = alloc(); // int r = construct({arr[2], arr[6], arr[8]}); // ans[a] = { // construct({arr[0], arr[1], arr[3], arr[4], arr[5], arr[7], oind, // aind}), r}; // ans[o] = {aind, ans[a].first}; // return oind; if (sz(arr) >= 9 && sz(arr) % 4 == 1) { auto [a, aind] = alloc(); vector<int> l, r; for (int i = 2; i < sz(arr); i += 4) { l.push_back(arr[i]); } l.push_back(arr.back()); for (int i = 0; i + 1 < sz(arr); i += 4) { r.push_back(arr[i]); r.push_back(arr[i + 1]); r.push_back(arr[i + 3]); } r.push_back(oind); r.push_back(aind); swap(l, r); dbg(sz(l), sz(r)); ans[a] = {construct(l), construct(r)}; ans[o] = {aind, ans[a].first}; return oind; } // if (sz(arr) == 10) { // auto [a, aind] = alloc(); // int r = construct({arr[2], arr[6], arr[9]}); // ans[a] = {construct({arr[0], arr[1], arr[3], arr[4], arr[5], arr[7], // arr[8], aind}), // r}; // ans[o] = {aind, ans[a].first}; // return oind; // } if (sz(arr) >= 10 && sz(arr) % 4 == 2) { auto [a, aind] = alloc(); vector<int> l, r; for (int i = 2; i < sz(arr); i += 4) { l.push_back(arr[i]); } l.push_back(arr.back()); for (int i = 0; i + 1 < sz(arr); i++) { if (i % 4 != 2) { r.push_back(arr[i]); } } r.push_back(aind); swap(l, r); dbg(sz(l), sz(r)); ans[a] = {construct(l), construct(r)}; ans[o] = {aind, ans[a].first}; return oind; } vector<int> l, r; for (int i = 0; i < sz(arr); i++) { if (i % 2 == 0) { l.push_back(arr[i]); } else { r.push_back(arr[i]); } } if (sz(arr) % 2 == 1) { r.push_back(l.back()); l.back() = oind; } ans[o] = {construct(l), construct(r)}; return oind; } void create_circuit(int m, vector<int> arr) { vector<int> nxt[m + 1]; arr.insert(arr.begin(), 0); arr.push_back(0); for (int i = 0; i < sz(arr) - 1; i++) { nxt[arr[i]].push_back(arr[i + 1]); } vector<int> ans1(m + 1); for (int i = 0; i <= m; i++) { if (sz(nxt[i])) { ans1[i] = construct(nxt[i]); } } vector<int> ans2, ans3; for (auto& [x, y] : ans) { ans2.push_back(x); ans3.push_back(y); } answer(ans1, ans2, ans3); }
#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...