//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
int n;
int ar[500005];
int freq[500005];
vector<pair<int,pair<char,char>>>ans;
stack<int>stkl;stack<int>stkr;
void swplr(){
ans.push_back({1,{'L','L'}});
ans.push_back({0,{'L','R'}});
stkr.push(stkl.top());
stkl.pop();
}
void swprl(){
ans.push_back({1,{'L','R'}});
ans.push_back({0,{'L','L'}});
stkl.push(stkr.top());
stkr.pop();
}
signed main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>n;
for(int i=n;i>=1;i--){
cin>>ar[i];
}
for(int i=1;i<=n;i++){
stkl.push(ar[i]);
freq[ar[i]]++;
}
for(int i=1;i<=n;i++){
swplr();
}
sort(ar+1,ar+n+1);
for(int i=n;i>=1;i--){
int rhand=0;
while(stkr.size()){
if(stkr.top()==ar[i]&&rhand==0){
ans.push_back({1,{'R','R'}});
rhand=1;
stkr.pop();
continue;
}
swprl();
}
while(stkl.size()){
swplr();
}
ans.push_back({0,{'R','L'}});
}
cout<<ans.size()<<endl;
for(int i=0;i<ans.size();i++){
if(ans[i].first==0){
cout<<"STAVI ";
}else{
cout<<"UZMI ";
}
if(ans[i].second.first=='R'){
cout<<"D ";
}else{
cout<<"L ";
}
if(ans[i].second.second=='R'){
cout<<"D\n";
}else{
cout<<"L\n";
}
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:61:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<char, char> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i=0;i<ans.size();i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
984 KB |
Output is correct |
2 |
Correct |
2 ms |
984 KB |
Output is correct |
3 |
Correct |
3 ms |
984 KB |
Output is correct |
4 |
Correct |
2 ms |
984 KB |
Output is correct |
5 |
Correct |
3 ms |
984 KB |
Output is correct |
6 |
Correct |
2 ms |
984 KB |
Output is correct |
7 |
Correct |
2 ms |
984 KB |
Output is correct |
8 |
Correct |
2 ms |
984 KB |
Output is correct |
9 |
Correct |
2 ms |
984 KB |
Output is correct |
10 |
Correct |
2 ms |
984 KB |
Output is correct |