結果

問題 No.930 数列圧縮
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-11-26 22:16:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,117 bytes
コンパイル時間 819 ms
コンパイル使用メモリ 72,940 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-06 21:50:23
合計ジャッジ時間 6,582 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 18 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,376 KB
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

constexpr int INF = 1 << 30;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i=0;i<n;++i){
        cin >> a[i];
    }

    int start = 0, i = 1;
    vector<int> ans;
    vector<int> rest(1, a[0]);
    bool is_succeeded = true;
    while(i < n) {
        if(a[i-1] > a[i]) {
            if(i-start < 2) {
                is_succeeded = false;
                break;
            }
            for(int j=start;j<i;++j) if(rest.back() != a[j]) ans.push_back(a[j]);
            rest.push_back((rest[0] < a[i]) ? a[i] : INF);
            start = i;
        }
        if((rest.size() == 1 || rest[0] < a[i]) && a[i] < rest.back()) rest.back() = a[i];
        ++i;
    }

    for(int j=start;j<n;++j) if(rest.back() != a[j]) ans.push_back(a[j]);

    if(!is_succeeded) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;

        for(int i=0;i<rest.size()-1;++i) ans.push_back(rest[i]);

        for(int x: ans) cout << x << " ";
        cout << endl;
    }


}
0