Submission #366277

#TimeUsernameProblemLanguageResultExecution timeMemory
366277model_codeKnjige (COCI20_knjige)C++17
50 / 50
32 ms1068 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000; int n, p[MAXN]; stack <int> l, d; vector <tuple <string, char, char> > potezi; void potez(string a, char b, char c) { potezi.push_back({a, b, c}); } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> p[i]; } for (int i = n - 1; i >= 0; i--) { l.push(p[i]); } sort(p, p + n); for (int i = 0; i < n; i++) { int prebacio = 0; while (l.top() != p[i]) { potez("UZMI", 'L', 'L'); potez("STAVI", 'L', 'D'); d.push(l.top()); l.pop(); prebacio++; } potez("UZMI", 'D', 'L'); l.pop(); for (int j = 0; j < prebacio; j++) { potez("UZMI", 'L', 'D'); potez("STAVI", 'L', 'L'); l.push(d.top()); d.pop(); } potez("STAVI", 'D', 'D'); d.push(p[i]); } while (!d.empty()) { potez("UZMI", 'L', 'D'); potez("STAVI", 'L', 'L'); l.push(d.top()); d.pop(); } cout << potezi.size() << endl; for (const auto &p : potezi) { cout << get<0>(p) << ' ' << get<1>(p) << ' ' << get<2>(p) << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...