# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
596379 | hail | Knjige (COCI20_knjige) | C++17 | 4 ms | 852 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 <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";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |