Submission #404039

#TimeUsernameProblemLanguageResultExecution timeMemory
404039ScarletSKnjige (COCI20_knjige)C++17
50 / 50
4 ms1484 KiB
#include <bits/stdc++.h> #define sz(x) (int)(x).size() using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; bool x; cin>>n; int a[n]; stack<int> s,t; vector<string> ans; for (int i=0;i<n;++i) cin>>a[i]; for (int i=n-1;i+1;--i) s.push(a[i]); sort(a,a+n,greater<int>()); for (int i=0;i<n;++i) { x=0; while (sz(s)>i) { if (s.top()==a[i]&&x==0) { ans.push_back("UZMI L L"); x=1; s.pop(); } else if (x) { ans.push_back("UZMI D L"); ans.push_back("STAVI D D"); t.push(s.top()); s.pop(); } else { ans.push_back("UZMI L L"); ans.push_back("STAVI L D"); t.push(s.top()); s.pop(); } } ans.push_back("STAVI L L"); s.push(a[i]); while (sz(t)) { ans.push_back("UZMI L D"); ans.push_back("STAVI L L"); s.push(t.top()); t.pop(); } } cout<<sz(ans)<<"\n"; for (string i : ans) cout<<i<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...