#include <bits/stdc++.h>
#define ST first
#define ND second
#define PB push_back
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
const int nax = 110;
int n, d[nax];
vector<tuple<bool,bool,bool>>moves;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; ++i) {
cin >> d[i];
}
int tp = 0;
int cnt = 0;
for(int step = 1; step <= n; ++step) {
cnt = 0;
vi ord;
int target = 1000000;
for(int i = tp; i < n; ++i) {
target = min(target, d[i]);
}
while(d[tp] != target) {
//cout << "UZMI L L\n";
ord.PB(d[tp]);
moves.PB({0,0,0});
moves.PB({1,0,1});
cnt++;
tp++;
}
moves.PB({0, 1, 0});
for(int i = 0; i < cnt; ++i) {
moves.PB({0, 0, 1});
moves.PB({1, 0, 0});
}
moves.PB({1, 1, 1});
tp -= (cnt - 1);
//reverse(ord.begin(), ord.end());
for(int i = tp; i < tp + cnt; ++i) {
d[i] = ord[i - tp];
}
}
for(int i = 0; i < n; ++i) {
moves.PB({0, 1, 1});
moves.PB({1, 1, 0});
}
cout << (int)moves.size() << "\n";
for(auto [x,y,z] : moves) {
if(x) cout << "STAVI ";
else cout << "UZMI ";
if(y) cout << "D ";
else cout << "L ";
if(z) cout << "D ";
else cout << "L ";
cout << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
472 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |