# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
453799 | RGBB | Knjige (COCI20_knjige) | C++14 | 3 ms | 780 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.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>pp;
typedef tuple<int,int,int>tt;//0-take 1-put, 0-left 1-right (hand), 0-left 1-right (shelf)
const int MAXN=100;
int n,a;
pp inp[MAXN],arr[MAXN];
stack<int>shelf[2];//0-left 1-right
vector<tt>outp;
void solve(int num)
{
int cnt=0;
while(shelf[1].top()!=num)
{
shelf[0].push(shelf[1].top());
shelf[1].pop();
outp.push_back(make_tuple(0,0,1));
outp.push_back(make_tuple(1,0,0));
cnt++;
}
shelf[1].pop();
outp.push_back(make_tuple(0,1,1));
for(int i=0;i<cnt;i++)
{
shelf[1].push(shelf[0].top());
shelf[0].pop();
outp.push_back(make_tuple(0,0,0));
outp.push_back(make_tuple(1,0,1));
}
shelf[0].push(num);
outp.push_back(make_tuple(1,1,0));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a;
inp[i]={-a,i};
arr[i]={-a,i};
}
sort(arr,arr+n);
map<pp,int>sorted;
for(int i=0;i<n;i++)sorted[arr[i]]=i;
//shit gets real
for(int i=0;i<n;i++)
{
shelf[1].push(sorted[inp[i]]);
outp.push_back(make_tuple(0,0,0));
outp.push_back(make_tuple(1,0,1));
}
for(int i=0;i<n;i++)solve(i);
cout<<outp.size()<<"\n";
for(tt i:outp)
{
if(get<0>(i)==0)cout<<"UZMI ";
else cout<<"STAVI ";
if(get<1>(i)==0)cout<<"L ";
else cout<<"D ";
if(get<2>(i)==0)cout<<"L\n";
else cout<<"D\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |