結果

問題 No.930 数列圧縮
ユーザー KKT89KKT89
提出日時 2020-07-05 03:29:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,740 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 115,072 KB
実行使用メモリ 4,732 KB
最終ジャッジ日時 2023-10-21 13:50:36
合計ジャッジ時間 4,472 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 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,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 15 ms
4,348 KB
testcase_09 AC 17 ms
4,348 KB
testcase_10 AC 14 ms
4,348 KB
testcase_11 AC 16 ms
4,348 KB
testcase_12 AC 18 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 20 ms
4,348 KB
testcase_16 AC 21 ms
4,528 KB
testcase_17 AC 22 ms
4,348 KB
testcase_18 AC 20 ms
4,348 KB
testcase_19 AC 22 ms
4,348 KB
testcase_20 AC 21 ms
4,348 KB
testcase_21 AC 21 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 21 ms
4,732 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int q=1;
    while(q--){
        int n; cin >> n;
        vector<int> a(n);
        for(int i=0;i<n;i++){
            cin >> a[i];
        }
        if(a[n-1]<a[0]){
            printf("No\n");
            return 0;
        }
        printf("Yes\n");
        vector<int> res;
        vector<int> v;
        v.push_back(a[n-1]);
        for(int i=n-2;i>=0;i--){
            if(v.size()==1&&v[0]>a[i]){
                res.push_back(a[i]);
                continue;
            }
            if(v.back()>a[i]){
                res.push_back(v.back());
                v.pop_back();
                v.push_back(a[i]);
                while(v.size()>2){
                    int sz=v.size();
                    int t=v.back();
                    if(v[sz-2]>v[sz-1]){
                        v.pop_back();
                        res.push_back(v.back());
                        v.pop_back();
                        v.push_back(t);
                    }
                    else{
                        break;
                    }
                }
                if(v.size()==2&&v[0]>v[1]){
                    res.push_back(v.back());
                    v.pop_back();
                }
            }
            else{
                v.push_back(a[i]);
            }
        }
        for(int i:res){
            printf("%d ",i);
        }
        printf("\n");
    }
}
0