#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
stack<int> left;
stack<int> right;
int n;
cin>>n;
vector<int> thickness(n);
for(int i=0; i<n ; i++)
{
cin>>thickness[i];
}
for(auto it=thickness.rbegin(); it!=thickness.rend(); it++)
{
left.push(*it);
}
sort(thickness.rbegin(), thickness.rend());
bool right_occupied;
int curr;
vector<tuple<int, int, int>> moves;
/*
tuple
0 - take(0) put(1)
1 - left(0) right(1)
2 - left(0) right(1)
*/
for(int i=0; i<n; i++)
{
right_occupied=false;
curr=thickness[i];
while((int)left.size()>i)
{
if(left.top()==curr && (not right_occupied))
{
moves.push_back(make_tuple(0, 1, 0));
right_occupied = true;
left.pop();
}
else
{
moves.push_back(make_tuple(0, 0, 0));
moves.push_back(make_tuple(1, 0, 1));
right.push(left.top());
left.pop();
}
}
moves.push_back(make_tuple(1, 1, 0));
left.push(curr);
while(not right.empty())
{
moves.push_back(make_tuple(0, 0, 1));
moves.push_back(make_tuple(1, 0, 0));
left.push(right.top());
right.pop();
}
}
cout<<moves.size()<<'\n';
for(auto& i: moves)
{
if(get<0>(i)) cout<<"STAVI ";
else cout<<"UZMI ";
if(get<1>(i)) cout<<"D ";
else cout<<"L ";
if(get<2>(i)) cout<<"D ";
else cout<<"L ";
cout<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
852 KB |
Output is correct |
2 |
Correct |
3 ms |
832 KB |
Output is correct |
3 |
Correct |
4 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
3 ms |
852 KB |
Output is correct |
7 |
Correct |
3 ms |
852 KB |
Output is correct |
8 |
Correct |
3 ms |
832 KB |
Output is correct |
9 |
Correct |
2 ms |
852 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |