Submission #1024040

# Submission time Handle Problem Language Result Execution time Memory
1024040 2024-07-15T10:44:51 Z kustizus Knjige (COCI20_knjige) C++17
50 / 50
3 ms 1764 KB
#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
1 Correct 2 ms 1504 KB Output is correct
2 Correct 2 ms 1504 KB Output is correct
3 Correct 2 ms 1764 KB Output is correct
4 Correct 2 ms 1504 KB Output is correct
5 Correct 2 ms 1508 KB Output is correct
6 Correct 2 ms 1508 KB Output is correct
7 Correct 2 ms 1508 KB Output is correct
8 Correct 2 ms 1504 KB Output is correct
9 Correct 3 ms 1508 KB Output is correct
10 Correct 2 ms 1508 KB Output is correct