# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
404039 | ScarletS | Knjige (COCI20_knjige) | C++17 | 4 ms | 1484 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>
#define sz(x) (int)(x).size()
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
bool x;
cin>>n;
int a[n];
stack<int> s,t;
vector<string> ans;
for (int i=0;i<n;++i)
cin>>a[i];
for (int i=n-1;i+1;--i)
s.push(a[i]);
sort(a,a+n,greater<int>());
for (int i=0;i<n;++i)
{
x=0;
while (sz(s)>i)
{
if (s.top()==a[i]&&x==0)
{
ans.push_back("UZMI L L");
x=1;
s.pop();
}
else if (x)
{
ans.push_back("UZMI D L");
ans.push_back("STAVI D D");
t.push(s.top());
s.pop();
}
else
{
ans.push_back("UZMI L L");
ans.push_back("STAVI L D");
t.push(s.top());
s.pop();
}
}
ans.push_back("STAVI L L");
s.push(a[i]);
while (sz(t))
{
ans.push_back("UZMI L D");
ans.push_back("STAVI L L");
s.push(t.top());
t.pop();
}
}
cout<<sz(ans)<<"\n";
for (string i : ans)
cout<<i<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |