# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
377409 | NONAME | Knjige (COCI20_knjige) | C++17 | 5 ms | 2024 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |