Submission #377388

# Submission time Handle Problem Language Result Execution time Memory
377388 2021-03-14T06:40:07 Z Vimmer Knjige (COCI20_knjige) C++14
50 / 50
7 ms 1024 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

#define N 100500
#define NN 1005000
#define PB push_back
#define M ll(1e9 + 7)
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define pri(x) cout << x << endl
#define endl '\n'
#define _ << " " <<
#define F first
#define S second

using namespace std;
//using namespace __gnu_pbds;

//typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> oredered_set;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef short int si;

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//    freopen("1.in", "r", stdin);

    int n;

    cin >> n;

    vector <int> a(n), vt(n);

    for (int i = 0; i < n; i++)
        {cin >> a[i]; vt[i] = a[i];}

    reverse(all(a));

    sort(all(vt));

    reverse(all(vt));

    int j = 0;

    vector <array <int, 3> > vr; vr.clear();

    while (j < n)
    {
        if (vt[j] != a[j])
        {
            int u = n - 1;

            vector <int> b; b.clear();

            bool ft = 0;

            while (u >= j)
            {
                if (!ft && a.back() == vt[j])
                {
                    vr.PB({0, 1, 0});

                    ft = 1;
                }
                else
                {
                    b.PB(a.back());

                    vr.PB({0, 0, 0});

                    vr.PB({1, 0, 1});
                }

                a.pop_back();

                u--;
            }

            assert(ft);

            vr.PB({1, 1, 0});

            a.PB(vt[j]);

            while (sz(b))
            {
                a.PB(b.back());

                b.pop_back();

                vr.PB({0, 0, 1});

                vr.PB({1, 0, 0});
            }
        }

        j++;
    }

    for (int i = 1; i < n; i++)
    {
        if (a[i - 1] < a[i])
            assert(0);
    }

    string st[2] = {"UZMI", "STAVI"};
    string t[2] = {"L", "D"};

    pri(sz(vr));

    for (auto it : vr)
    {
        pri(st[it[0]] _ t[it[1]] _ t[it[2]]);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 876 KB Output is correct
2 Correct 5 ms 876 KB Output is correct
3 Correct 5 ms 876 KB Output is correct
4 Correct 5 ms 872 KB Output is correct
5 Correct 5 ms 876 KB Output is correct
6 Correct 5 ms 876 KB Output is correct
7 Correct 4 ms 816 KB Output is correct
8 Correct 5 ms 872 KB Output is correct
9 Correct 5 ms 872 KB Output is correct
10 Correct 6 ms 1024 KB Output is correct