Submission #377409

#TimeUsernameProblemLanguageResultExecution timeMemory
377409NONAMEKnjige (COCI20_knjige)C++17
50 / 50
5 ms2024 KiB
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int n; vector <int> lft, rgt, need; vector <array <string, 3> > res; void shift(int x, vector <int>& v1, vector <int>& v2, int tp) { while ((int)(v1.size()) > (x + 1)) { res.push_back({"UZMI", "L", (tp ? "L" : "D")}); res.push_back({"STAVI", "L", (tp ? "D" : "L")}); v2.push_back(v1.back()); v1.pop_back(); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; lft.reserve(n); rgt.reserve(n); for (int i = 0; i < n; ++i) { int x; cin >> x; lft.push_back(x); need.push_back(x); } sort(need.rbegin(), need.rend()); reverse(lft.begin(), lft.end()); while (!lft.empty()) { res.push_back({"UZMI", "L", "L"}); res.push_back({"STAVI", "L", "D"}); rgt.push_back(lft.back()); lft.pop_back(); } // for (int i = 0; i < (int)(rgt.size()); ++i) { // cerr << rgt[i] << " "; // } // cerr << "\n"; for (auto& c : need) { int ps = -1; for (int i = 0; i < (int)(rgt.size()); ++i) { if (rgt[i] == c) { ps = i; } } int cnt = ((int)(rgt.size()) - 1) - ps; // cerr << ps << " " << cnt << "\n"; shift(ps, rgt, lft, 0); // R -> L rgt.pop_back(); res.push_back({"UZMI", "D", "D"}); shift(((int)(lft.size()) - 1) - cnt, lft, rgt, 1); // L -> R lft.push_back(c); res.push_back({"STAVI", "D", "L"}); } // for (int i = 0; i < (int)(lft.size()); ++i) { // cerr << lft[i] << " "; // } // cerr << "\n"; cout << (int)(res.size()) << "\n"; for (int i = 0; i < (int)(res.size()); ++i) { cout << res[i][0] << " " << res[i][1] << " " << res[i][2] << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...