답안 #405672

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
405672 2021-05-16T16:58:20 Z souvenir_vayne Knjige (COCI20_knjige) C++14
50 / 50
33 ms 460 KB
#include<bits/stdc++.h>

using namespace std;

int32_t main() {

    int n;
    cin >> n;

    long long ans = 0;
    for(int i = 0; i < n; i++)
        ans += 2 * (n - i) + 2*(n - i - 1);
    cout << ans << endl;

    stack<int> left, right;

    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        left.push(x);
    }

    stack<int> aux;
    while(!left.empty()) {
        aux.push(left.top());
        left.pop();
    }

    left = aux;

    int did = 0;
    while(did < n) {

        int mn = 0;

        aux = left;
        while(!aux.empty()) {
            mn = max(mn, aux.top());
            aux.pop();
        }

        bool taken = false;
        for(int i = 0; i < n - did; i++) {
            if(left.top() == mn && !taken) {
                taken = true;
                cout << "UZMI L L" << endl;
            }
            else {
                cout << "UZMI D L" << endl << "STAVI D D" << endl;
                right.push(left.top());
            }
            left.pop();
        }

        did++;
        cout << "STAVI L L" << endl;


        while(!right.empty()) {
            cout << "UZMI D D" << endl << "STAVI D L" << endl;
            left.push(right.top());
            right.pop();
        }

    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 412 KB Output is correct
2 Correct 33 ms 408 KB Output is correct
3 Correct 33 ms 460 KB Output is correct
4 Correct 32 ms 352 KB Output is correct
5 Correct 32 ms 452 KB Output is correct
6 Correct 33 ms 380 KB Output is correct
7 Correct 31 ms 452 KB Output is correct
8 Correct 32 ms 460 KB Output is correct
9 Correct 33 ms 408 KB Output is correct
10 Correct 32 ms 460 KB Output is correct