# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
615399 | ak2006 | Knjige (COCI20_knjige) | C++14 | 29 ms | 1448 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;
vector<string>ans;
void f(vector<int> a,int n)
{
if (n <= 1)return;
int mx = 0,pos = 0;
for (int i = 0;i<n;i++){
if (a[i] > mx)pos = i;
mx = max(mx,a[i]);
}
for (int i = 0;i<pos;i++){
//move from left shelf to hand = UZMI L L
//move from hand to right shelf = STAVI L D
ans.push_back("UZMI L L");
ans.push_back("STAVI L D");
}
ans.push_back("UZMI D L");
for (int i = pos + 1;i<n;i++){
//move from left shelf to left hand = UZMI L L
//move from left hand to right shelf = STAVI L D
ans.push_back("UZMI L L");
ans.push_back("STAVI L D");
}
ans.push_back("STAVI D L");
for (int i = 0;i<n - 1;i++){
//move from right shelf to left hand = UZMI D L
//move from left hand to left shelf = STAVI L L
ans.push_back("UZMI L D");
ans.push_back("STAVI L L");
}
vector<int> nxt;
for (int i = 0;i<n;i++){
if (pos == i)continue;
nxt.push_back(a[i]);
}
f(nxt,n - 1);
}
int main()
{
int n;
cin>>n;
vector<int> a(n);
for (int i = 0;i<n;i++)cin>>a[i];
f(a,n);
cout<<ans.size()<<endl;
for (auto it:ans)cout<<it<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |