Submission #377461

# Submission time Handle Problem Language Result Execution time Memory
377461 2021-03-14T08:46:22 Z VEGAnn Knjige (COCI20_knjige) C++14
50 / 50
4 ms 876 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
#define all(x) x.begin(),x.end()
#define i2 array<int,2>
#define i3 array<int,3>
using namespace std;
typedef long long ll;
const int oo = 2e9;
const int N = 110;
const int M = 10;
const int PW = 10;
const int HPW = 233;
const int md = int(1e9) + 7;
vector<int> who;
vector<i3> events;
int n, a[N], nm[N];

bool cmp(int _x, int _y){
    return (a[_x] < a[_y]);
}

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

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n;

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

    sort(nm + 1, nm + n + 1, cmp);

    for (int i = 1; i <= n; i++)
        a[nm[i]] = i;

    /// 0 -- UZMI, 1 -- STAV
    /// 0 -- L, 1 -- R
    /// 0 -- L, 1 -- R

    for (int it = n; it > 0; it--){
        who.clear();

        bool was = 0;

        for (int i = 1; i <= it; i++) {
            assert(a[i] <= it);

            if (a[i] == it) {
                events.PB({0, 0, 0});
                was = 1;
            } else {
                events.PB({0, 1, 0});
                events.PB({1, 1, 1});
                who.PB(a[i]);
            }
        }

        events.PB({1, 0, 0});
        a[it] = it;

        assert(was);

        reverse(all(who));

        for (int jy = 0; jy < sz(who); jy++){
            events.PB({0, 1, 1});
            events.PB({1, 1, 0});

            a[sz(who) - jy] = who[jy];
        }
    }

    cout << sz(events) << '\n';

    for (i3 cr : events){
        if (cr[0])
            cout << "STAVI ";
        else cout << "UZMI ";

        if (cr[1])
            cout << "D ";
        else cout << "L ";

        if (cr[2])
            cout << "D\n";
        else cout << "L\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 876 KB Output is correct
2 Correct 3 ms 876 KB Output is correct
3 Correct 4 ms 876 KB Output is correct
4 Correct 3 ms 876 KB Output is correct
5 Correct 4 ms 876 KB Output is correct
6 Correct 3 ms 876 KB Output is correct
7 Correct 4 ms 876 KB Output is correct
8 Correct 4 ms 876 KB Output is correct
9 Correct 3 ms 876 KB Output is correct
10 Correct 3 ms 876 KB Output is correct