Submission #398677

#TimeUsernameProblemLanguageResultExecution timeMemory
398677egorlifarThe Collection Game (BOI21_swaps)C++17
15 / 100
15 ms500 KiB
// // --- Sample implementation for the task swaps --- // // To compile this program with the sample grader, place: // swaps.h swaps_sample.cpp sample_grader.cpp // in a single folder and run: // g++ swaps_sample.cpp sample_grader.cpp // in this folder. // #include "swaps.h" #include <iostream> #include <complex> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <numeric> #include <cstring> #include <ctime> #include <cstdlib> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <list> #include <cmath> #include <bitset> #include <cassert> #include <queue> #include <stack> #include <deque> #include <random> using namespace std; template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;} template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;} #define files(FILENAME) read(FILENAME); write(FILENAME) #define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin) #define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout) #define all(c) (c).begin(), (c).end() #define sz(c) (int)(c).size() #define left left228 #define right right228 #define y1 y1228 #define mp make_pair #define pb push_back #define y2 y2228 #define rank rank228 using ll = long long; using ld = long double; const string FILENAME = "input"; const int MAXN = 2005; vector<pair<int, vector<int> > > who[MAXN]; vector<int> ans[MAXN]; void preparestor(int v, vector<int> vals, int deep) { if (sz(vals) <= 1) { ans[v] = vals; return; } vector<int> vals1, vals2; for (int i = 0; i < sz(vals) / 2; i++) { vals1.pb(vals[i]); } for (int i = sz(vals) / 2; i < sz(vals); i++) { vals2.pb(vals[i]); } preparestor(v * 2, vals1, deep + 1); preparestor(v * 2 + 1, vals2, deep + 1); who[deep].pb(mp(v, vals)); } int uk[MAXN]; int uk1[MAXN]; void solve(int n, int v) { vector<int> vals; for (int i = 1; i <= n; i++) { vals.pb(i); } preparestor(1, vals, 0); for (int f = 30; f >= 0; f--) { if (!who[f].empty()) { for (int j = 0; j < sz(who[f]); j++) { uk[j] = 0; uk1[j] = 0; } while (true) { bool was = false; vector<int> st; for (int j = 0; j < sz(who[f]); j++) { int v = who[f][j].first; if (uk[j] == sz(ans[v * 2])) { while (uk1[j] < sz(ans[v * 2 + 1])) { ans[v].pb(ans[v * 2 + 1][uk1[j]]); uk1[j]++; } continue; } if (uk1[j] == sz(ans[v * 2 + 1])) { while (uk[j] < sz(ans[v * 2])) { ans[v].pb(ans[v * 2][uk[j]]); uk[j]++; } continue; } was = true; schedule(ans[v * 2][uk[j]], ans[v * 2 + 1][uk1[j]]); st.pb(j); } if (was) { auto ff = visit(); int fk = 0; for (auto x: st) { int v = who[f][x].first; if (ff[fk]) { ans[v].pb(ans[v * 2][uk[x]]); uk[x]++; } else { ans[v].pb(ans[v * 2 + 1][uk1[x]]); uk1[x]++; } fk++; } } else { break; } } } } answer(ans[1]); }
#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...
#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...