結果

問題 No.921 ずんだアロー
ユーザー brthyyjpbrthyyjp
提出日時 2020-03-15 19:47:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 584 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 97,872 KB
最終ジャッジ日時 2023-08-16 19:16:21
合計ジャッジ時間 4,179 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,112 KB
testcase_01 AC 70 ms
71,252 KB
testcase_02 AC 72 ms
71,344 KB
testcase_03 AC 75 ms
71,336 KB
testcase_04 AC 72 ms
71,096 KB
testcase_05 AC 70 ms
71,216 KB
testcase_06 AC 68 ms
71,204 KB
testcase_07 AC 69 ms
71,256 KB
testcase_08 AC 67 ms
71,248 KB
testcase_09 AC 69 ms
71,240 KB
testcase_10 AC 136 ms
96,520 KB
testcase_11 AC 111 ms
97,708 KB
testcase_12 AC 81 ms
77,304 KB
testcase_13 AC 89 ms
85,716 KB
testcase_14 AC 106 ms
94,756 KB
testcase_15 AC 87 ms
82,264 KB
testcase_16 AC 78 ms
76,588 KB
testcase_17 AC 104 ms
96,152 KB
testcase_18 AC 107 ms
97,872 KB
testcase_19 AC 109 ms
97,668 KB
testcase_20 AC 110 ms
97,576 KB
testcase_21 AC 110 ms
97,776 KB
testcase_22 AC 110 ms
97,484 KB
testcase_23 AC 109 ms
97,580 KB
testcase_24 AC 105 ms
97,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int, input().split()))

if n == 1:
    print(1)
    exit()

dp = [[0, 0] for _ in range(n)]
# dp[i][0]: i個目をずんだ餅にしなかったときのi個目までの最大値
# dp[i][1]: i個目をすんだ餅にしたときのi個目までの最大値

dp[0][0] = 0
dp[0][1] = 1

for i in range(1, n):
    if A[i-1] != A[i]:
        dp[i][0] = max(dp[i-1][0], dp[i-1][1])
        dp[i][1] = max(dp[i-1][0]+1, dp[i-1][1])
    else:
        dp[i][0] = max(dp[i-1][0], dp[i-1][1])
        dp[i][1] = max(dp[i-1][0]+1, dp[i-1][1]+1)

print(max(dp[-1]))
0