結果

問題 No.930 数列圧縮
ユーザー MisterMister
提出日時 2020-08-04 18:14:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 956 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 84,788 KB
実行使用メモリ 8,572 KB
最終ジャッジ日時 2023-10-12 21:26:33
合計ジャッジ時間 5,026 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 54 ms
6,964 KB
testcase_09 AC 64 ms
7,532 KB
testcase_10 AC 49 ms
6,740 KB
testcase_11 AC 54 ms
7,028 KB
testcase_12 AC 65 ms
7,496 KB
testcase_13 WA -
testcase_14 AC 43 ms
6,500 KB
testcase_15 AC 54 ms
8,192 KB
testcase_16 AC 56 ms
8,104 KB
testcase_17 AC 83 ms
8,352 KB
testcase_18 AC 81 ms
8,380 KB
testcase_19 AC 81 ms
8,572 KB
testcase_20 AC 82 ms
8,348 KB
testcase_21 AC 82 ms
8,388 KB
testcase_22 AC 2 ms
4,356 KB
testcase_23 AC 58 ms
8,180 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 1 ms
4,352 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()) {
            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