結果

問題 No.930 数列圧縮
ユーザー chocoruskchocorusk
提出日時 2019-03-29 00:12:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,362 bytes
コンパイル時間 740 ms
コンパイル使用メモリ 97,548 KB
実行使用メモリ 11,516 KB
最終ジャッジ日時 2023-08-07 07:42:08
合計ジャッジ時間 3,413 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
5,436 KB
testcase_02 AC 2 ms
5,428 KB
testcase_03 AC 2 ms
5,696 KB
testcase_04 AC 2 ms
5,500 KB
testcase_05 AC 3 ms
7,528 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
7,536 KB
testcase_08 AC 31 ms
9,508 KB
testcase_09 AC 38 ms
10,188 KB
testcase_10 AC 32 ms
9,912 KB
testcase_11 AC 33 ms
10,288 KB
testcase_12 AC 38 ms
10,324 KB
testcase_13 AC 15 ms
4,380 KB
testcase_14 AC 18 ms
4,380 KB
testcase_15 AC 43 ms
10,580 KB
testcase_16 AC 46 ms
10,464 KB
testcase_17 AC 48 ms
11,516 KB
testcase_18 AC 47 ms
10,864 KB
testcase_19 AC 48 ms
11,416 KB
testcase_20 AC 47 ms
11,004 KB
testcase_21 AC 44 ms
10,596 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 43 ms
10,292 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int n;
int mx[18][100002];
int a[100002];
vector<int> ans;
void solve(int p, int l, int r){
    if(l>=r) return;
    if(p==0) ans.push_back(a[l]);
    else ans.push_back(a[r]);
    if(l+1==r) return;
    if(a[l]<a[r-1]){
        solve(1, l, r-1);
        return;
    }
    int m=r-1;
    for(int i=17; i>=0; i--){
        if(m-(1<<i)+1<0 || mx[i][m]>=a[l]) continue;
        m-=(1<<i);
    }
    solve(1, l, m);
    solve(0, m+1, r);
}
int main()
{
    cin>>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;
    for(int i=0; i<n; i++){
        mx[0][i]=a[i];
        for(int j=1; i-(1<<j)+1>=0; j++){
            mx[j][i]=max(mx[j-1][i], mx[j-1][i-(1<<(j-1))]);
        }
    }
    solve(0, 0, n-1);
    for(int i=n-2; i>=0; i--){
        cout<<ans[i];
        if(i>0) cout<<" ";
    }
    cout<<endl;
    return 0;
}
0