結果

問題 No.921 ずんだアロー
ユーザー ttrttr
提出日時 2020-01-31 20:31:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 11,848 KB
実行使用メモリ 21,656 KB
最終ジャッジ日時 2023-10-17 08:29:34
合計ジャッジ時間 4,802 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,140 KB
testcase_01 AC 29 ms
10,140 KB
testcase_02 AC 29 ms
10,140 KB
testcase_03 AC 30 ms
10,140 KB
testcase_04 AC 30 ms
10,140 KB
testcase_05 AC 29 ms
10,140 KB
testcase_06 AC 29 ms
10,164 KB
testcase_07 AC 29 ms
10,144 KB
testcase_08 AC 29 ms
10,140 KB
testcase_09 AC 29 ms
10,144 KB
testcase_10 AC 161 ms
20,744 KB
testcase_11 AC 167 ms
21,292 KB
testcase_12 AC 58 ms
12,448 KB
testcase_13 AC 128 ms
18,124 KB
testcase_14 AC 143 ms
19,236 KB
testcase_15 AC 94 ms
15,296 KB
testcase_16 AC 38 ms
10,844 KB
testcase_17 AC 142 ms
19,336 KB
testcase_18 AC 175 ms
21,656 KB
testcase_19 AC 180 ms
21,656 KB
testcase_20 AC 175 ms
21,656 KB
testcase_21 AC 174 ms
21,652 KB
testcase_22 AC 175 ms
21,656 KB
testcase_23 AC 172 ms
21,636 KB
testcase_24 AC 178 ms
21,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = [int(a) for a in input().split()]

dp0 = [0]*N #i番目をずんだ餅にした時のずんだ餅の個数の最大値
dp1 = [0]*N #i番目をずんだ餅にしなかった時のずんだ餅の個数の最大値
dp0[0] = 1
for i in range(1, N):
    if A[i-1] == A[i]:
        dp0[i] = max(dp0[i-1]+1, dp1[i-1]+1)
        dp1[i] = max(dp0[i-1], dp1[i-1])
    else:
        dp0[i] = max(dp0[i-1], dp1[i-1]+1)
        dp1[i] = max(dp0[i-1], dp1[i-1])

print(max(dp0[N-1], dp1[N-1]))
0