#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 time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1068 KB |
Output is correct |
2 |
Correct |
25 ms |
1068 KB |
Output is correct |
3 |
Correct |
26 ms |
1068 KB |
Output is correct |
4 |
Correct |
24 ms |
1068 KB |
Output is correct |
5 |
Correct |
24 ms |
1068 KB |
Output is correct |
6 |
Correct |
32 ms |
1068 KB |
Output is correct |
7 |
Correct |
17 ms |
812 KB |
Output is correct |
8 |
Correct |
24 ms |
1068 KB |
Output is correct |
9 |
Correct |
31 ms |
1016 KB |
Output is correct |
10 |
Correct |
24 ms |
1068 KB |
Output is correct |