結果

問題 No.930 数列圧縮
ユーザー ei13337ei13337
提出日時 2019-11-22 22:32:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 775 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 87,660 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 12:02:42
合計ジャッジ時間 2,701 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 25 ms
6,944 KB
testcase_09 AC 29 ms
6,940 KB
testcase_10 AC 24 ms
6,944 KB
testcase_11 AC 26 ms
6,944 KB
testcase_12 AC 30 ms
6,940 KB
testcase_13 AC 14 ms
6,940 KB
testcase_14 AC 17 ms
6,944 KB
testcase_15 AC 36 ms
6,940 KB
testcase_16 AC 36 ms
6,944 KB
testcase_17 AC 36 ms
6,944 KB
testcase_18 AC 37 ms
6,944 KB
testcase_19 AC 36 ms
6,944 KB
testcase_20 AC 36 ms
6,940 KB
testcase_21 AC 36 ms
6,944 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 36 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    if(a[0] > a[n - 1]) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    stack<int> st;
    vector<int> ans;
    st.push(a[0]);
    for(int i = 1; i < n - 1; i++) {
        if(a[i] > st.top()) ans.push_back(a[i]);
        else st.push(a[i]);
    }
    while(!st.empty()) {
        ans.push_back(st.top());
        st.pop();
    }
    for(int i = 0; i < (int)ans.size(); i++) {
        if(i) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}
0