Submission #1024040

#TimeUsernameProblemLanguageResultExecution timeMemory
1024040kustizusKnjige (COCI20_knjige)C++17
50 / 50
3 ms1764 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 100; int n, a[N + 5]; vector<string> ans; void Solve(int move) { if (move == n + 1) return; vector<int> v; int val = 0, pos; for (int i = 1; i <= n - move + 1; ++i) if (a[i] > val) { val = a[i]; pos = i; } if (pos == n - move + 1) { Solve(move + 1); return; } for (int i = 1; i < pos; ++i) { v.push_back(a[i]); 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 - move + 1; ++i) { v.push_back(a[i]); ans.push_back("UZMI L L"); ans.push_back("STAVI L D"); } ans.push_back("STAVI D L"); a[n - move + 1] = val; for (int i = n - move; i >= 1; i--) { ans.push_back("UZMI L D"); ans.push_back("STAVI L L"); a[i] = v.back(); v.pop_back(); } Solve(move + 1); } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // freopen("file.inp", "r", stdin); // freopen("file.out", "w", stdout); cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; Solve(1); cout << ans.size() << "\n"; for (string s : ans) cout << s << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...