結果

問題 No.930 数列圧縮
ユーザー MisterMister
提出日時 2020-08-04 18:18:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 84,176 KB
実行使用メモリ 8,492 KB
最終ジャッジ日時 2023-10-12 21:29:02
合計ジャッジ時間 3,904 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,356 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 55 ms
6,948 KB
testcase_09 AC 63 ms
7,592 KB
testcase_10 AC 49 ms
6,560 KB
testcase_11 AC 55 ms
6,992 KB
testcase_12 AC 65 ms
7,600 KB
testcase_13 AC 34 ms
5,948 KB
testcase_14 AC 43 ms
6,744 KB
testcase_15 AC 55 ms
8,064 KB
testcase_16 AC 55 ms
8,136 KB
testcase_17 AC 83 ms
8,400 KB
testcase_18 AC 87 ms
8,492 KB
testcase_19 AC 82 ms
8,356 KB
testcase_20 AC 82 ms
8,344 KB
testcase_21 AC 81 ms
8,316 KB
testcase_22 AC 2 ms
4,356 KB
testcase_23 AC 60 ms
8,068 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>

void solve() {
    int n;
    std::cin >> n;

    std::set<int> rem;
    for (int i = 1; i <= n; ++i) rem.insert(i);

    std::vector<int> ans;
    std::vector<int> stk;
    while (n--) {
        int x;
        std::cin >> x;
        rem.erase(x);

        if (stk.empty() || x < stk.back()) {
            stk.push_back(x);

        } else if (rem.lower_bound(stk.front()) == rem.end()) {
            if (x < stk.front()) {
                std::cout << "No\n";
                return;
            }

            while (!stk.empty()) {
                ans.push_back(stk.back());
                stk.pop_back();
            }
            stk.push_back(x);

        } else {
            ans.push_back(x);
        }
    }

    if (stk.size() != 1) {
        std::cout << "No\n";
    } else {
        std::cout << "Yes\n";
        for (auto a : ans) std::cout << a << " ";
        std::cout << "\n";
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0