結果

問題 No.324 落ちてた閉路グラフ
ユーザー kuuso1kuuso1
提出日時 2015-12-17 23:38:53
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 2,740 bytes
コンパイル時間 2,917 ms
コンパイル使用メモリ 109,916 KB
実行使用メモリ 450,176 KB
最終ジャッジ日時 2023-10-14 12:57:59
合計ジャッジ時間 14,727 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
22,644 KB
testcase_01 AC 50 ms
22,764 KB
testcase_02 AC 49 ms
20,804 KB
testcase_03 AC 54 ms
22,628 KB
testcase_04 AC 634 ms
198,392 KB
testcase_05 AC 1,446 ms
450,176 KB
testcase_06 AC 526 ms
160,568 KB
testcase_07 AC 1,347 ms
422,784 KB
testcase_08 AC 527 ms
167,196 KB
testcase_09 AC 242 ms
83,592 KB
testcase_10 AC 544 ms
165,084 KB
testcase_11 AC 235 ms
83,728 KB
testcase_12 RE -
testcase_13 AC 58 ms
22,928 KB
testcase_14 AC 133 ms
56,524 KB
testcase_15 AC 239 ms
90,104 KB
testcase_16 RE -
testcase_17 AC 52 ms
20,720 KB
testcase_18 AC 50 ms
20,668 KB
testcase_19 AC 50 ms
20,840 KB
testcase_20 RE -
testcase_21 AC 51 ms
20,580 KB
testcase_22 AC 51 ms
20,652 KB
testcase_23 AC 53 ms
22,616 KB
testcase_24 RE -
testcase_25 AC 50 ms
20,580 KB
testcase_26 AC 50 ms
20,832 KB
testcase_27 AC 51 ms
22,692 KB
testcase_28 AC 49 ms
20,620 KB
testcase_29 RE -
testcase_30 AC 51 ms
18,692 KB
testcase_31 AC 50 ms
20,776 KB
testcase_32 AC 1,405 ms
435,844 KB
testcase_33 AC 1,162 ms
366,340 KB
testcase_34 AC 524 ms
175,028 KB
testcase_35 AC 57 ms
21,020 KB
testcase_36 AC 143 ms
57,600 KB
testcase_37 AC 50 ms
20,728 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(){
		
		int[][][] dp=new int[N+1][][];
		for(int i=0;i<=N;i++){
			dp[i]=new int[M+1][];
			for(int j=0;j<=M;j++){
				dp[i][j]=new int[2];
				dp[i][j][0]=dp[i][j][1]=-Inf;
			}
		}
		
		//1つめを取った場合
		dp[0][1][1]=0;
		
		for(int i=0;i<N-1;i++){
			for(int j=0;j<=Min(M,i+1);j++){
				dp[i+1][j][0]=Max(dp[i+1][j][0],dp[i][j][0]);
				if(j<M)dp[i+1][j+1][1]=Max(dp[i+1][j+1][1],dp[i][j][0]);
				dp[i+1][j][0]=Max(dp[i+1][j][0],dp[i][j][1]);
				if(j<M)dp[i+1][j+1][1]=Max(dp[i+1][j+1][1],dp[i][j][1]+A[i]);
			}
		}
		for(int j=0;j<=M;j++){
			dp[N][j][0]=Max(dp[N][j][0],dp[N-1][j][0]);
			dp[N][j][1]=Max(dp[N][j][1],dp[N-1][j][1]+A[N-1]);
		}
		
		int ans1=Max(dp[N][M][0],dp[N][M][1]);
		
		//1つめを取らなかった場合
		for(int i=0;i<=N;i++){
			for(int j=0;j<=M;j++){
				dp[i][j][0]=dp[i][j][1]=-Inf;
			}
		}
		
		dp[0][0][0]=0;
		
		for(int i=0;i<N-1;i++){
			for(int j=0;j<=Min(M,i+1);j++){
				dp[i+1][j][0]=Max(dp[i+1][j][0],dp[i][j][0]);
				if(j<M)dp[i+1][j+1][1]=Max(dp[i+1][j+1][1],dp[i][j][0]);
				dp[i+1][j][0]=Max(dp[i+1][j][0],dp[i][j][1]);
				if(j<M)dp[i+1][j+1][1]=Max(dp[i+1][j+1][1],dp[i][j][1]+A[i]);
			}
		}
		for(int j=0;j<=M;j++){
			dp[N][j][0]=Max(dp[N][j][0],dp[N-1][j][0]);
			dp[N][j][1]=Max(dp[N][j][1],dp[N-1][j][1]);
		}
		
		int ans0=Max(dp[N][M][0],dp[N][M][1]);
		
		Console.WriteLine(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();
	}
	static int Max(int x,int y){return x>y?x:y;}
	static int Min(int x,int y){return x<y?x:y;}
	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