# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
704900 | 1075508020060209tc | Knjige (COCI20_knjige) | C++14 | 3 ms | 984 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |