# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1024040 | kustizus | Knjige (COCI20_knjige) | C++17 | 3 ms | 1764 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 int long long
using namespace std;
const int N = 100;
int n, a[N + 5];
vector<string> ans;
void Solve(int move)
{
if (move == n + 1)
return;
vector<int> v;
int val = 0, pos;
for (int i = 1; i <= n - move + 1; ++i)
if (a[i] > val)
{
val = a[i];
pos = i;
}
if (pos == n - move + 1)
{
Solve(move + 1);
return;
}
for (int i = 1; i < pos; ++i)
{
v.push_back(a[i]);
ans.push_back("UZMI L L");
ans.push_back("STAVI L D");
}
ans.push_back("UZMI D L");
for (int i = pos + 1; i <= n - move + 1; ++i)
{
v.push_back(a[i]);
ans.push_back("UZMI L L");
ans.push_back("STAVI L D");
}
ans.push_back("STAVI D L");
a[n - move + 1] = val;
for (int i = n - move; i >= 1; i--)
{
ans.push_back("UZMI L D");
ans.push_back("STAVI L L");
a[i] = v.back();
v.pop_back();
}
Solve(move + 1);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("file.inp", "r", stdin);
// freopen("file.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
Solve(1);
cout << ans.size() << "\n";
for (string s : ans)
cout << s << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |