# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
872482 | aeg | Knjige (COCI20_knjige) | C++17 | 1 ms | 752 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;
int main() {
int n;
cin >> n;
deque<int> l(n);
stack<int> r;
for(int i=0; i<n; i++) cin >> l[i];
while(!l.empty() && *max_element(l.begin(), l.end()) == l.back()) {
l.pop_back();
}
int cnt = 0;
string ans;
while(!l.empty()){
int cur = *max_element(l.begin(), l.end());
if(cur == l.back()) {
l.pop_back();
continue;
}
while(l.front()!=cur) {
ans += "UZMI L L\n";
ans += "STAVI L D\n";
cnt += 2;
r.push(l.front());
l.pop_front();
}
ans += "UZMI D L\n";
cnt ++;
l.pop_front();
while(!l.empty()) {
ans += "UZMI L L\n";
ans += "STAVI L D\n";
cnt += 2;
r.push(l.front());
l.pop_front();
}
ans += "STAVI D L\n";
cnt ++;
while(!r.empty()) {
ans += "UZMI L D\n";
ans += "STAVI L L\n";
cnt += 2;
l.push_front(r.top());
r.pop();
}
}
cout << cnt << endl << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |