結果

問題 No.324 落ちてた閉路グラフ
ユーザー kuuso1kuuso1
提出日時 2015-12-17 23:54:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 388 ms / 5,000 ms
コード長 2,798 bytes
コンパイル時間 905 ms
コンパイル使用メモリ 115,772 KB
実行使用メモリ 100,704 KB
最終ジャッジ日時 2024-04-27 16:03:06
合計ジャッジ時間 5,096 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
24,312 KB
testcase_01 AC 22 ms
24,240 KB
testcase_02 AC 23 ms
24,316 KB
testcase_03 AC 23 ms
26,212 KB
testcase_04 AC 214 ms
57,036 KB
testcase_05 AC 388 ms
100,704 KB
testcase_06 AC 181 ms
52,320 KB
testcase_07 AC 351 ms
90,880 KB
testcase_08 AC 191 ms
55,404 KB
testcase_09 AC 99 ms
37,236 KB
testcase_10 AC 187 ms
55,532 KB
testcase_11 AC 99 ms
30,976 KB
testcase_12 AC 27 ms
18,944 KB
testcase_13 AC 25 ms
18,816 KB
testcase_14 AC 54 ms
27,264 KB
testcase_15 AC 78 ms
32,128 KB
testcase_16 AC 22 ms
18,304 KB
testcase_17 AC 22 ms
18,176 KB
testcase_18 AC 22 ms
18,432 KB
testcase_19 AC 21 ms
18,176 KB
testcase_20 AC 21 ms
18,176 KB
testcase_21 AC 22 ms
18,304 KB
testcase_22 AC 21 ms
18,176 KB
testcase_23 AC 21 ms
18,048 KB
testcase_24 AC 21 ms
18,176 KB
testcase_25 AC 21 ms
18,176 KB
testcase_26 AC 21 ms
18,176 KB
testcase_27 AC 20 ms
18,304 KB
testcase_28 AC 21 ms
18,048 KB
testcase_29 AC 22 ms
18,304 KB
testcase_30 AC 21 ms
18,176 KB
testcase_31 AC 26 ms
18,176 KB
testcase_32 AC 364 ms
98,832 KB
testcase_33 AC 351 ms
98,532 KB
testcase_34 AC 183 ms
54,876 KB
testcase_35 AC 27 ms
18,944 KB
testcase_36 AC 65 ms
27,648 KB
testcase_37 AC 22 ms
18,048 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;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		if(M==0){
			Console.WriteLine(0);return;
		}
		int[][][] dp=new int[2][][];
		for(int i=0;i<2;i++){
			dp[i]=new int[N+1][];
			for(int j=0;j<=N;j++){
				dp[i][j]=new int[M+1];
				for(int k=0;k<=M;k++)dp[i][j][k]=-Inf;
			}
		}
		
		//1つめを取った場合
		dp[1][0][1]=0;
		
		for(int i=0;i<N-1;i++){
			for(int j=0;j<=Math.Min(M,i+1);j++){
				dp[0][i+1][j]=Math.Max(dp[0][i+1][j],dp[0][i][j]);
				if(j<M)dp[1][i+1][j+1]=Math.Max(dp[1][i+1][j+1],dp[0][i][j]);
				dp[0][i+1][j]=Math.Max(dp[0][i+1][j],dp[1][i][j]);
				if(j<M)dp[1][i+1][j+1]=Math.Max(dp[1][i+1][j+1],dp[1][i][j]+A[i]);
			}
		}
		for(int j=0;j<=M;j++){
			dp[0][N][j]=Math.Max(dp[0][N][j],dp[0][N-1][j]);
			dp[1][N][j]=Math.Max(dp[1][N][j],dp[1][N-1][j]+A[N-1]);
		}
		
		int ans1=Math.Max(dp[0][N][M],dp[1][N][M]);
		
		//1つめを取らなかった場合
		for(int i=0;i<2;i++){
			for(int j=0;j<=N;j++){
				for(int k=0;k<=M;k++)dp[i][j][k]=-Inf;
			}
		}
		
		dp[0][0][0]=0;
		
		for(int i=0;i<N-1;i++){
			for(int j=0;j<=Math.Min(M,i+1);j++){
				dp[0][i+1][j]=Math.Max(dp[0][i+1][j],dp[0][i][j]);
				if(j<M)dp[1][i+1][j+1]=Math.Max(dp[1][i+1][j+1],dp[0][i][j]);
				dp[0][i+1][j]=Math.Max(dp[0][i+1][j],dp[1][i][j]);
				if(j<M)dp[1][i+1][j+1]=Math.Max(dp[1][i+1][j+1],dp[1][i][j]+A[i]);
			}
		}
		for(int j=0;j<=M;j++){
			dp[0][N][j]=Math.Max(dp[0][N][j],dp[0][N-1][j]);
			dp[1][N][j]=Math.Max(dp[1][N][j],dp[1][N-1][j]);
		}
		
		int ans0=Math.Max(dp[0][N][M],dp[1][N][M]);
		
		Console.WriteLine(Math.Max(ans0,ans1));
		
	}
	int N,M;
	int[] A;
	static int Inf=(int)1e9;
	
	public Sol(){
		var d=ria();
		N=d[0];M=d[1];
		A=ria();
	}

	void dbg(int[][][] dp){
		for(int m=M;m>=0;m--){
				for(int n=0;n<=N;n++){
					Console.Write("{0} ",dp[n][m][0]==-Inf?"X":dp[n][m][0].ToString());
				}
				Console.WriteLine();
				for(int n=0;n<=N;n++){
					Console.Write("{0} ",dp[n][m][1]==-Inf?"X":dp[n][m][1].ToString());
				}
				Console.WriteLine();
				Console.WriteLine();
		}Console.WriteLine();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
0