結果

問題 No.393 2本の竹
ユーザー hiyokko2hiyokko2
提出日時 2016-07-30 20:02:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 831 bytes
コンパイル時間 230 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 54,504 KB
最終ジャッジ日時 2024-04-24 13:13:19
合計ジャッジ時間 3,203 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
16,896 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 100 ms
11,368 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def rec(i, r1):
	#if dp[i][r1] != -1:
	#	return dp[i][r1]
	if i in dphash and r1 in dphash[i]:
		return dphash[i][r1]
	r2 = n1 + n2 - Asum[i - 1] - r1
	if i == m:
		res = 0
	elif max(r1, r2) < A[i]:
		res = 0
	elif r1 < A[i] and A[i] < r2:
		res = rec(i + 1, r1) + 1
	elif r2 < A[i] and A[i] < r1:
		res = rec(i + 1, r1 - A[i]) + 1
	else:
		res = max(rec(i + 1, r1), rec(i + 1, r1 - A[i])) + 1
	#dp[i][r1] = res
	if i in dphash:
		dphash[i][r1] = res
	else:
		dphash[i] = {}
		dphash[i][r1] = res
	return res

d = int(input())
for _ in range(d):
	n1, n2 = map(int, input().split())
	m = int(input())
	A = sorted(map(int, input().split()))

	Asum = []
	Asum.append(A[0])
	for i in range(1, m):
		Asum.append(Asum[i - 1] + A[i])
	#print(Asum)
	#dp = [[-1 for r1 in range(100001)] for i in range(61)]
	dphash = {}
	print(rec(0, n1))

0