結果

問題 No.1148 土偶Ⅲ
ユーザー 双六双六
提出日時 2020-08-09 01:53:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 718 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 82,280 KB
実行使用メモリ 90,556 KB
最終ジャッジ日時 2024-04-10 11:14:24
合計ジャッジ時間 3,469 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,704 KB
testcase_01 AC 39 ms
54,912 KB
testcase_02 AC 39 ms
53,984 KB
testcase_03 AC 39 ms
54,364 KB
testcase_04 AC 39 ms
55,036 KB
testcase_05 AC 67 ms
76,616 KB
testcase_06 AC 92 ms
90,556 KB
testcase_07 AC 79 ms
85,216 KB
testcase_08 AC 90 ms
88,140 KB
testcase_09 AC 84 ms
86,704 KB
testcase_10 AC 66 ms
78,072 KB
testcase_11 AC 83 ms
87,004 KB
testcase_12 AC 48 ms
64,852 KB
testcase_13 AC 51 ms
68,788 KB
testcase_14 AC 49 ms
66,428 KB
testcase_15 AC 74 ms
83,348 KB
testcase_16 AC 55 ms
71,868 KB
testcase_17 AC 91 ms
88,944 KB
testcase_18 AC 48 ms
64,780 KB
testcase_19 AC 66 ms
78,808 KB
testcase_20 AC 75 ms
82,216 KB
testcase_21 AC 65 ms
77,908 KB
testcase_22 AC 52 ms
65,932 KB
testcase_23 AC 52 ms
67,596 KB
testcase_24 AC 55 ms
69,952 KB
testcase_25 AC 54 ms
72,204 KB
testcase_26 AC 75 ms
81,480 KB
testcase_27 AC 50 ms
66,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, W = getlist()
	A = []
	D = defaultdict(int)
	for i in range(N):
		a = int(input())
		A.append(a)

	i = 0; j = 0
	val = 0
	ans = 0
	jud = 0
	while True:
		if val > W or jud == 1:
			if i >= N:
				break
			D[A[i]] -= 1; val -= A[i]
			if D[A[i]] == 1:
				jud = 0
			i += 1
		else:
			if j >= N:
				break
			D[A[j]] += 1; val += A[j]
			if D[A[j]] == 2:
				jud = 1
			else:
				if val <= W:
					ans = max(ans, j - i + 1)

			j += 1

	print(ans)

if __name__ == '__main__':
	main()
0