結果

問題 No.324 落ちてた閉路グラフ
ユーザー TawaraTawara
提出日時 2015-12-17 01:57:44
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 1,954 ms / 5,000 ms
コード長 548 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 77,324 KB
実行使用メモリ 123,232 KB
最終ジャッジ日時 2023-08-09 21:34:47
合計ジャッジ時間 19,671 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
76,424 KB
testcase_01 AC 73 ms
76,420 KB
testcase_02 AC 73 ms
76,300 KB
testcase_03 AC 74 ms
76,196 KB
testcase_04 AC 1,860 ms
123,232 KB
testcase_05 AC 202 ms
79,400 KB
testcase_06 AC 1,896 ms
115,608 KB
testcase_07 AC 790 ms
84,740 KB
testcase_08 AC 1,930 ms
117,280 KB
testcase_09 AC 1,081 ms
89,256 KB
testcase_10 AC 1,954 ms
117,928 KB
testcase_11 AC 1,111 ms
89,052 KB
testcase_12 AC 74 ms
77,356 KB
testcase_13 AC 87 ms
79,144 KB
testcase_14 AC 75 ms
77,732 KB
testcase_15 AC 90 ms
79,016 KB
testcase_16 AC 74 ms
76,468 KB
testcase_17 AC 74 ms
76,372 KB
testcase_18 AC 71 ms
76,248 KB
testcase_19 AC 73 ms
76,156 KB
testcase_20 AC 74 ms
76,060 KB
testcase_21 AC 75 ms
76,564 KB
testcase_22 AC 74 ms
76,288 KB
testcase_23 AC 73 ms
76,616 KB
testcase_24 AC 74 ms
76,516 KB
testcase_25 AC 74 ms
76,540 KB
testcase_26 AC 74 ms
76,268 KB
testcase_27 AC 75 ms
76,264 KB
testcase_28 AC 75 ms
76,460 KB
testcase_29 AC 76 ms
76,608 KB
testcase_30 AC 73 ms
76,392 KB
testcase_31 AC 74 ms
76,260 KB
testcase_32 AC 436 ms
80,428 KB
testcase_33 AC 1,387 ms
100,772 KB
testcase_34 AC 1,478 ms
107,720 KB
testcase_35 AC 93 ms
79,256 KB
testcase_36 AC 598 ms
82,864 KB
testcase_37 AC 87 ms
79,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,raw_input().split())
w = map(int,raw_input().split())
if m == 0:
	print 0
	quit()
if m == n:
	print sum(w)
	quit()
def solve(start):
	dp = {(m-start,start):0}
	for i in xrange(n-1):
		tmp_dp = dict()
		for (k,h),v in dp.iteritems():
			for nxt in xrange(2):
				if 0 <= k-nxt < n-1-i:
					nk = (k-nxt,nxt)
					nv =  v + (w[i] if h*nxt == 1 else 0)
					if nk not in tmp_dp or tmp_dp[nk] < nv:
						tmp_dp[nk] = nv
		dp = tmp_dp
	return max(v + (w[n-1] if h*start else 0) for (k,h),v in dp.iteritems())
print max(solve(0), solve(1))
0