# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
452045 | PiejanVDC | Knjige (COCI20_knjige) | C++17 | 2 ms | 712 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;
signed main() {
int n; cin>>n;
vector<int>sorted(n);
stack<int>l,r;
for(int i = 0 ; i < n ; i++) {
cin>>sorted[i];
}
for(int i = n-1 ; i >= 0 ; i--) l.push(sorted[i]);
vector<string>ans;
// rechts ==> nemen
// links ==> vasthouden
int cnt=0;
sort(sorted.rbegin(),sorted.rend());
bool f = true;
for(int i = 0 ; i < n ; i++) {
int t = sorted[i];
if(f) {
for(int j = 0 ; j < n - i ; j++) {
if(l.top() != t) r.push(l.top()), ans.push_back("UZMI D L\nSTAVI D D\n"),cnt+=2;
else ans.push_back("UZMI L L\n"),cnt++;
l.pop();
}
ans.push_back("STAVI L L\n");
cnt++;
l.push(t);
f=false;
} else {
while(true) {
if(r.top() == t) break;
ans.push_back("UZMI D D\nSTAVI D L\n");
cnt+=2;
l.push(r.top());
r.pop();
}
ans.push_back("UZMI L D\n");
cnt++;
r.pop();
while(l.size() > i) {
r.push(l.top());
l.pop();
ans.push_back("UZMI D L\nSTAVI D D\n");
cnt+=2;
}
l.push(t);
ans.push_back("STAVI L L\n");
cnt++;
}
}
//while(!l.empty()) cout << l.top() << " ",l.pop();
cout << cnt << "\n";
//reverse(ans.begin(),ans.end());
for(auto z : ans) cout << z;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |