結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 54 ms
6,928 KB
testcase_09 AC 64 ms
7,436 KB
testcase_10 AC 49 ms
6,668 KB
testcase_11 AC 55 ms
6,964 KB
testcase_12 AC 65 ms
7,656 KB
testcase_13 AC 35 ms
6,188 KB
testcase_14 WA -
testcase_15 AC 54 ms
8,120 KB
testcase_16 AC 55 ms
8,300 KB
testcase_17 AC 85 ms
8,316 KB
testcase_18 AC 82 ms
8,456 KB
testcase_19 AC 82 ms
8,352 KB
testcase_20 AC 82 ms
8,380 KB
testcase_21 AC 82 ms
8,384 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 58 ms
8,048 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 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, 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);
        }
    }

    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