Submission #377389

# Submission time Handle Problem Language Result Execution time Memory
377389 2021-03-14T06:40:21 Z ne4eHbKa Knjige (COCI20_knjige) C++17
50 / 50
6 ms 1768 KB
#include <bits/stdc++.h>
using namespace std;
#ifndef _LOCAL
//#pragma GCC optimize("O3,Ofast")
#else
#pragma GCC optimize("O0")
#endif
template<typename t> inline void umin(t &a, const t b) {a = min(a, b);}
template<typename t> inline void umax(t &a, const t b) {a = max(a, b);}
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef int8_t byte;
ll time() {return chrono::system_clock().now().time_since_epoch().count();}
mt19937 rnd(time());
#define ft first
#define sd second
#define len(f) int((f).size())
#define bnd(f) (f).begin(), (f).end()
#define _ <<' '<<
const int inf = 1e9 + 5;
const ll inf64 = 4e18 + 5;
const int md = 998244353;
namespace MD {
    void add(int &a, const int b) {if((a += b) >= md) a -= md;}
    void sub(int &a, const int b) {if((a -= b) < 0) a += md;}
    int prod(const int a, const int b) {return ll(a) * b % md;}
};

vector<int> a[2];
int b[2];
vector<string> ans;

void take(int fi, int se) {
    ans.push_back((string)"UZMI " + (fi ? 'D' : 'L') + ' ' + (se ? 'D' : 'L') + '\n');
    b[fi] = a[se].back();
    a[se].pop_back();
}

void put(int fi, int se) {
    ans.push_back((string)"STAVI " + (fi ? 'D' : 'L') + ' ' + (se ? 'D' : 'L') + '\n');
    a[se].push_back(b[fi]);
    b[fi] = -1;
}

void solve() {
    int n; cin >> n;
    a[0].resize(n);
    for(int &i : a[0]) cin >> i;
    vector<int> f(n);
    iota(bnd(f), 0);
    sort(bnd(f), [&] (const int &l, const int &r) {return a[0][l] < a[0][r];});
    for(int i = 0; i < n; ++i) a[0][f[i]] = i + 1;
    reverse(bnd(a[0]));
    for(int i = 0; i < n; ++i) {
        while(a[0].back() != i + 1)
            take(0, 0),
            put(0, 1);
        take(1, 0);
        while(i ? a[1].back() != i : len(a[1]))
            take(0, 1),
            put(0, 0);
        put(1, 0);
        while(len(a[1]))
            take(0, 1),
            put(0, 0);
    }
    cout << len(ans) << endl;
    for(auto i : ans) cout << i;
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef _LOCAL
//    freopen("file.in", "r", stdin);
//    freopen("file.out", "w", stdout);
#else
    system("color a");
    freopen("in.txt", "r", stdin);
    int t; cin >> t;
    while(t--)
#endif
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1768 KB Output is correct
2 Correct 6 ms 1768 KB Output is correct
3 Correct 6 ms 1768 KB Output is correct
4 Correct 6 ms 1640 KB Output is correct
5 Correct 6 ms 1640 KB Output is correct
6 Correct 6 ms 1768 KB Output is correct
7 Correct 6 ms 1768 KB Output is correct
8 Correct 6 ms 1640 KB Output is correct
9 Correct 6 ms 1768 KB Output is correct
10 Correct 6 ms 1640 KB Output is correct