#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
#define fastIO ios::sync_with_stdio(false), cin.tie(NULL)
#define forw(i, l, r) for( int i = (l) ; i < (r) ; i++ )
#define forb(i, r, l) for( int i = (r) ; i >= (l) ; i-- )
#define log2i(x) (64 - __builtin_clzll(1ll * (x)) - 1)
#define numBit(x) (__builtin_popcountll(1ll * (x)))
#define getBit(x, i) ((x) >> (i) & 1)
#define Pi acos(-1.0l)
#define sz(x) int(x.size())
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define debug(x) cerr << #x << " = " << x << '\n';
const int N = 107;
char C[] = {'L', 'D'};
int n;
int a[N], hand[2] = {-1, -1};
stack<int> shelf[2];
vector<tuple<string, char, char> > ans;
int take(bool h, bool s) {
ans.pb(mt("UZMI", C[h], C[s]));
assert(sz(shelf[s]));
assert(hand[h] == -1);
int book = shelf[s].top();
shelf[s].pop();
hand[h] = book;
return book;
}
void put(bool h, bool s) {
ans.pb(mt("STAVI", C[h], C[s]));
assert(hand[h] != -1);
shelf[s].push(hand[h]);
hand[h] = -1;
}
int main() {
fastIO;
#ifndef ONLINE_JUDGE
//freopen("test.inp","r",stdin);
//freopen("test.out","w",stdout);
#endif
cin >> n;
forw(i, 0, n) cin >> a[i];
forb(i, n - 1, 0) shelf[0].push(a[i]);
sort(a, a + n, greater<int>());
forw(i, 0, n) take(0, 0), put(0, 1);
forw(i, 0, n) {
int num = 0;
for(; take(0, 1) != a[i]; num++) put(0, 0);
while(num--) take(1, 0), put(1, 1);
put(0, 0);
}
cout << sz(ans) << '\n';
for(auto x:ans) {
string st; char c1, c2;
tie(st, c1, c2) = x;
cout << st << ' ' << c1 << ' ' << c2 << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1036 KB |
Output is correct |
2 |
Correct |
4 ms |
1036 KB |
Output is correct |
3 |
Correct |
3 ms |
1036 KB |
Output is correct |
4 |
Correct |
4 ms |
1036 KB |
Output is correct |
5 |
Correct |
3 ms |
1036 KB |
Output is correct |
6 |
Correct |
3 ms |
1036 KB |
Output is correct |
7 |
Correct |
2 ms |
780 KB |
Output is correct |
8 |
Correct |
4 ms |
1036 KB |
Output is correct |
9 |
Correct |
4 ms |
1036 KB |
Output is correct |
10 |
Correct |
3 ms |
1036 KB |
Output is correct |