Submission #872482

#TimeUsernameProblemLanguageResultExecution timeMemory
872482aegKnjige (COCI20_knjige)C++17
50 / 50
1 ms752 KiB
#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 timeMemoryGrader output
Fetching results...