답안 #377430

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377430 2021-03-14T08:08:24 Z kartel Knjige (COCI20_knjige) C++14
50 / 50
4 ms 688 KB
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
//#include <time.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
//#define M ll(1e9 + 7)
#define M ll(998244353)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define arr_all(x, n) (x + 1), (x + 1 + n)
#define vi vector<int>
#define eps (ld)1e-9
using namespace std;
typedef long long ll;
//using namespace __gnu_pbds;
//typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef double ld;
typedef unsigned long long ull;
typedef short int si;

const int N = 105;

string fans[4] = {"UZMI", "STAVI", "L", "D"};
int nans[4] = {0, 1, 2, 3};

int a[N], n;

int main()
{
//    mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());;
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	in("toys.in");
//	out("toys.out");
//    in("input.txt");
//    out("output.txt");
//    cerr.precision(9); cerr << fixed;

//    clock_t tStart = clock();

    cin >> n;

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

    vector <pair <int, pii> > ans;
    vector <int> st1;
    vector <int> st2;

    for (int i = 1; i <= n; i++) {
        ans.pb({0, {2, 2}});
        ans.pb({1, {2, 3}});
        st2.pb(a[i]);
    }

    sort(arr_all(a, n));
    reverse(arr_all(a, n));

    for (int i = 1; i <= n; i++) {
        while (st2.back() != a[i]) {
            ans.pb({0, {2, 3}});
            ans.pb({1, {2, 2}});

            st1.pb(st2.back());
            st2.pop_back();
        }
        ans.pb({0, {2, 3}});
        st2.pop_back();

        while (sz(st1) >= i) {
            ans.pb({0, {3, 2}});
            ans.pb({1, {3, 3}});

            st2.pb(st1.back());
            st1.pop_back();
        }

        ans.pb({1, {2, 2}});
        st1.pb(a[i]);
    }

    cout << sz(ans) << el;

    for (auto x : ans) {
        cout << fans[x.F] << " " << fans[x.S.F] << " " << fans[x.S.S] << el;
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 688 KB Output is correct
2 Correct 3 ms 688 KB Output is correct
3 Correct 3 ms 688 KB Output is correct
4 Correct 3 ms 688 KB Output is correct
5 Correct 3 ms 688 KB Output is correct
6 Correct 3 ms 688 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 3 ms 688 KB Output is correct
9 Correct 4 ms 688 KB Output is correct
10 Correct 3 ms 688 KB Output is correct