結果

問題 No.324 落ちてた閉路グラフ
ユーザー pekempeypekempey
提出日時 2015-12-17 01:20:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,331 ms / 5,000 ms
コード長 1,170 bytes
コンパイル時間 2,010 ms
コンパイル使用メモリ 110,624 KB
実行使用メモリ 164,024 KB
最終ジャッジ日時 2024-04-27 15:57:56
合計ジャッジ時間 31,428 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 486 ms
161,828 KB
testcase_01 AC 473 ms
164,024 KB
testcase_02 AC 469 ms
161,692 KB
testcase_03 AC 474 ms
161,920 KB
testcase_04 AC 1,254 ms
162,304 KB
testcase_05 AC 2,331 ms
162,432 KB
testcase_06 AC 1,065 ms
162,432 KB
testcase_07 AC 2,147 ms
162,560 KB
testcase_08 AC 1,099 ms
162,432 KB
testcase_09 AC 752 ms
162,304 KB
testcase_10 AC 1,093 ms
162,432 KB
testcase_11 AC 739 ms
162,560 KB
testcase_12 AC 473 ms
162,432 KB
testcase_13 AC 475 ms
162,432 KB
testcase_14 AC 625 ms
162,304 KB
testcase_15 AC 742 ms
162,432 KB
testcase_16 AC 482 ms
161,792 KB
testcase_17 AC 473 ms
162,048 KB
testcase_18 AC 484 ms
162,048 KB
testcase_19 AC 473 ms
161,792 KB
testcase_20 AC 473 ms
161,920 KB
testcase_21 AC 476 ms
161,664 KB
testcase_22 AC 480 ms
162,048 KB
testcase_23 AC 470 ms
161,920 KB
testcase_24 AC 476 ms
161,920 KB
testcase_25 AC 475 ms
161,792 KB
testcase_26 AC 481 ms
162,048 KB
testcase_27 AC 479 ms
162,048 KB
testcase_28 AC 477 ms
161,920 KB
testcase_29 AC 463 ms
162,048 KB
testcase_30 AC 474 ms
162,048 KB
testcase_31 AC 472 ms
161,792 KB
testcase_32 AC 2,210 ms
162,304 KB
testcase_33 AC 1,931 ms
162,304 KB
testcase_34 AC 1,115 ms
162,688 KB
testcase_35 AC 484 ms
162,304 KB
testcase_36 AC 626 ms
162,176 KB
testcase_37 AC 431 ms
161,920 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
	class Program
	{
		static void Main(string[] args)
		{
			new Program().Solve();
		}

		void Solve()
		{
			string[] tmp = Console.ReadLine().Split();
			int n = int.Parse(tmp[0]);
			int m = int.Parse(tmp[1]);
			int[] w = Console.ReadLine().Split().Select(int.Parse).ToArray();

			const int Inf = (int)1e9;

			var dp = new int[3030, 3030, 2, 2];
			for (int i = 0; i < 3030; i++)
			for (int j = 0; j < 3030; j++)
			for (int k = 0; k < 2; k++)
			for (int l = 0; l < 2; l++)
				dp[i, j, k, l] = -Inf;

			dp[0, 0, 0, 0] = dp[0, 1, 1, 1] = 0;

			for (int i = 1; i < n; i++)
			for (int j = 0; j <= m; j++)
			for (int k = 0; k <= 1; k++)
			for (int l = 0; l <= 1; l++)
			{
				dp[i, j, 0, l] = Math.Max(dp[i, j, 0, l], dp[i - 1, j, k, l]);
				dp[i, j + 1, 1, l] = Math.Max(dp[i, j + 1, 1, l], dp[i - 1, j, k, l] + w[i] * k);
			}
			int ans = -Inf;
			for (int k = 0; k <= 1; k++)
				for (int l = 0; l <= 1; l++)
					ans = Math.Max(ans, dp[n - 1, m, k, l] + k * l * w[0]);
			Console.WriteLine(ans);
		}
	}
}
0