#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
signed main(){
fastio
int n;
cin >> n;
multiset<int> s;
int arr[n];
stack<int> st, st2;
for(int i = 0;i < n;i++){
cin >> arr[i];
s.insert(arr[i]);
}
for(int i = n-1;~i;i--) st.push(arr[i]);
vector<pair<string,pair<char,char>>> v;
while(!st.empty()){
if(st.top()!=*s.begin()){
v.push_back({"UZMI",{'L','L'}});
v.push_back({"STAVI",{'L','D'}});
st2.push(st.top());
st.pop();
}else{
v.push_back({"UZMI",{'D','L'}});
s.erase(s.find(st.top()));
st.pop();
while(!st2.empty()){
v.push_back({"UZMI",{'L','D'}});
v.push_back({"STAVI",{'L','L'}});
st.push(st2.top());
st2.pop();
}
v.push_back({"STAVI",{'D','D'}});
}
}
for(int i = 0;i < n;i++){
v.push_back({"UZMI",{'L','D'}});
v.push_back({"STAVI",{'L','L'}});
}
cout << v.size() << "\n";
for(auto p : v){
cout << p.first << " " << p.second.first << " " << p.second.second << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1064 KB |
Output is correct |
2 |
Correct |
4 ms |
1064 KB |
Output is correct |
3 |
Correct |
4 ms |
1064 KB |
Output is correct |
4 |
Correct |
4 ms |
1064 KB |
Output is correct |
5 |
Correct |
4 ms |
1064 KB |
Output is correct |
6 |
Correct |
4 ms |
1064 KB |
Output is correct |
7 |
Correct |
3 ms |
844 KB |
Output is correct |
8 |
Correct |
4 ms |
1064 KB |
Output is correct |
9 |
Correct |
4 ms |
1124 KB |
Output is correct |
10 |
Correct |
4 ms |
1084 KB |
Output is correct |