Submission #377408

# Submission time Handle Problem Language Result Execution time Memory
377408 2021-03-14T07:33:07 Z NONAME Knjige (COCI20_knjige) C++17
0 / 50
7 ms 2152 KB
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int n;
vector <int> lft, rgt, need;
vector <array <string, 3> > res;

void shift(int x, vector <int>& v1, vector <int>& v2, int tp) {
    while ((int)(v1.size()) > (x + 1)) {
        res.push_back({"UZMI", "L", (tp ? "L" : "R")});
        res.push_back({"STAVI", "L", (tp ? "R" : "L")});
        v2.push_back(v1.back());
        v1.pop_back();
    }
}

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

    cin >> n;
    lft.reserve(n);
    rgt.reserve(n);
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        lft.push_back(x);
        need.push_back(x);
    }
    sort(need.rbegin(), need.rend());
    reverse(lft.begin(), lft.end());

    while (!lft.empty()) {
        res.push_back({"UZMI", "L", "L"});
        res.push_back({"STAVI", "L", "R"});
        rgt.push_back(lft.back());
        lft.pop_back();
    }

    // for (int i = 0; i < (int)(rgt.size()); ++i) {
    //     cerr << rgt[i] << " ";
    // }
    // cerr << "\n";

    for (auto& c : need) {
        int ps = -1;
        for (int i = 0; i < (int)(rgt.size()); ++i) {
            if (rgt[i] == c) {
                ps = i;
            }
        }

        int cnt = ((int)(rgt.size()) - 1) - ps;
        // cerr << ps << " " << cnt << "\n";
        shift(ps, rgt, lft, 0); // R -> L
        rgt.pop_back();
        res.push_back({"UZMI", "D", "R"});
        shift(((int)(lft.size()) - 1) - cnt, lft, rgt, 1); // L -> R
        lft.push_back(c);
        res.push_back({"STAVI", "D", "L"});
    }

    // for (int i = 0; i < (int)(lft.size()); ++i) {
    //     cerr << lft[i] << " ";
    // }
    // cerr << "\n";
    
    cout << (int)(res.size()) << "\n";
    for (int i = 0; i < (int)(res.size()); ++i) {
        cout << res[i][0] << " " << res[i][1] << " " << res[i][2] << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2024 KB Token "R" doesn't correspond to pattern "(L|D)"
2 Incorrect 4 ms 2024 KB Token "R" doesn't correspond to pattern "(L|D)"
3 Incorrect 6 ms 2024 KB Token "R" doesn't correspond to pattern "(L|D)"
4 Incorrect 4 ms 2024 KB Token "R" doesn't correspond to pattern "(L|D)"
5 Incorrect 4 ms 2024 KB Token "R" doesn't correspond to pattern "(L|D)"
6 Incorrect 4 ms 2024 KB Token "R" doesn't correspond to pattern "(L|D)"
7 Incorrect 4 ms 1260 KB Token "R" doesn't correspond to pattern "(L|D)"
8 Incorrect 5 ms 2024 KB Token "R" doesn't correspond to pattern "(L|D)"
9 Incorrect 7 ms 2152 KB Token "R" doesn't correspond to pattern "(L|D)"
10 Incorrect 4 ms 2024 KB Token "R" doesn't correspond to pattern "(L|D)"