# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
844741 | vjudge1 | Knjige (COCI20_knjige) | C++17 | 3 ms | 1752 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;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll MAXN = 5005;
vector<int> A, srt;
string put(string hand, string shelf) {
return "STAVI " + hand + " " + shelf + "\n";
}
string take(string hand, string shelf) {
return "UZMI " + hand + " " + shelf + "\n";
}
int main() {
fast
int N;
cin >> N;
A = vector<int>(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
srt.push_back(A[i]);
}
sort(srt.begin(), srt.end());
stack<int> l, r;
vector<string> ans;
for (int i = 0; i < N; i++)
l.push(A[i]);
while (l.size() || r.size()) {
while (l.size() && srt.back() != l.top()) {
ans.push_back(take("L", "L"));
ans.push_back(put("L", "R"));
r.push(l.top());
l.pop();
}
ans.push_back(take("R", "L"));
l.pop();
while (l.size()) {
ans.push_back(take("L", "L"));
ans.push_back(put("L", "R"));
r.push(l.top());
l.pop();
}
ans.push_back(put("R", "L"));
while (r.size()) {
ans.push_back(take("L", "R"));
ans.push_back(put("L", "L"));
l.push(r.top());
r.pop();
}
srt.pop_back();
}
cout << ans.size() << "\n";
for (auto u : ans)
cout << u;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |