結果

問題 No.930 数列圧縮
ユーザー stngstng
提出日時 2022-08-15 11:52:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,676 KB
実行使用メモリ 95,168 KB
最終ジャッジ日時 2024-04-09 23:41:16
合計ジャッジ時間 3,869 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,788 KB
testcase_01 AC 41 ms
54,740 KB
testcase_02 AC 41 ms
54,072 KB
testcase_03 AC 38 ms
55,400 KB
testcase_04 AC 39 ms
55,032 KB
testcase_05 AC 50 ms
65,592 KB
testcase_06 AC 43 ms
61,076 KB
testcase_07 AC 60 ms
69,268 KB
testcase_08 AC 88 ms
88,512 KB
testcase_09 AC 91 ms
88,124 KB
testcase_10 AC 89 ms
87,980 KB
testcase_11 AC 85 ms
89,156 KB
testcase_12 AC 88 ms
92,092 KB
testcase_13 AC 72 ms
80,800 KB
testcase_14 AC 72 ms
81,768 KB
testcase_15 AC 90 ms
94,796 KB
testcase_16 AC 97 ms
94,608 KB
testcase_17 AC 105 ms
87,172 KB
testcase_18 AC 105 ms
88,184 KB
testcase_19 AC 98 ms
92,600 KB
testcase_20 AC 96 ms
95,024 KB
testcase_21 AC 88 ms
94,828 KB
testcase_22 AC 40 ms
55,732 KB
testcase_23 AC 88 ms
95,168 KB
testcase_24 AC 40 ms
55,348 KB
testcase_25 AC 37 ms
53,924 KB
testcase_26 AC 37 ms
54,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())
a = [int(i) for i in input().split()]

now = a[0]
ans = []
idx = 1
d = deque()
for i in range(n*10):
    if idx >= n:
        break
    if a[idx] == 0:
        idx += 1
        continue
    if now < a[idx]:
        ans.append(a[idx])
        a[idx] = 0
    else:
        if idx+1 >= n:
            break
        if a[idx] < a[idx+1]:
            ans.append(a[idx])
            a[idx] = 0
            while len(d):
                tmp = d.pop()
                if tmp < a[idx+1]:
                    ans.append(tmp)
                else:
                    d.append(tmp)
                    break
        else:
            d.append(a[idx])
        idx += 1

if len(ans) != n-1:
    print("No")
else:
    print("Yes")
    print(*ans)
0