結果

問題 No.1148 土偶Ⅲ
ユーザー 👑 H20H20
提出日時 2022-01-27 23:55:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 417 bytes
コンパイル時間 1,240 ms
コンパイル使用メモリ 86,576 KB
実行使用メモリ 92,204 KB
最終ジャッジ日時 2023-08-27 02:33:24
合計ジャッジ時間 5,616 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,404 KB
testcase_01 AC 96 ms
71,156 KB
testcase_02 AC 95 ms
71,260 KB
testcase_03 AC 94 ms
71,288 KB
testcase_04 AC 93 ms
71,480 KB
testcase_05 AC 147 ms
81,264 KB
testcase_06 AC 186 ms
92,204 KB
testcase_07 AC 162 ms
87,648 KB
testcase_08 AC 168 ms
90,204 KB
testcase_09 AC 155 ms
88,876 KB
testcase_10 AC 139 ms
81,372 KB
testcase_11 AC 161 ms
89,064 KB
testcase_12 AC 116 ms
77,496 KB
testcase_13 AC 122 ms
77,836 KB
testcase_14 AC 121 ms
77,560 KB
testcase_15 AC 141 ms
86,308 KB
testcase_16 AC 127 ms
79,428 KB
testcase_17 AC 165 ms
90,132 KB
testcase_18 AC 115 ms
77,464 KB
testcase_19 AC 134 ms
82,132 KB
testcase_20 AC 143 ms
84,120 KB
testcase_21 AC 138 ms
81,368 KB
testcase_22 AC 119 ms
77,404 KB
testcase_23 AC 122 ms
77,860 KB
testcase_24 AC 125 ms
78,196 KB
testcase_25 AC 132 ms
78,404 KB
testcase_26 AC 161 ms
80,828 KB
testcase_27 AC 127 ms
77,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections

N,W = map(int, input().split())
A = []
for _ in range(N):
    A.append(int(input()))
D = collections.defaultdict(int)
ans = 0
j = 0
s = 0
for i in range(N+1):
    while j<N and s<=W and D[A[j]]==0:
        D[A[j]]=1
        s+=A[j]
        if s<=W:
            ans = max(ans,j-i+1)
        j += 1
    if i==N:
        break
    s -= A[i]
    D[A[i]]=0

if ans<=1:
    print(0)
else:
    print(ans)
0