Submission #615399

#TimeUsernameProblemLanguageResultExecution timeMemory
615399ak2006Knjige (COCI20_knjige)C++14
50 / 50
29 ms1448 KiB
#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 timeMemoryGrader output
Fetching results...