結果

問題 No.324 落ちてた閉路グラフ
ユーザー 37zigen37zigen
提出日時 2016-03-21 12:38:23
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,505 bytes
コンパイル時間 2,334 ms
コンパイル使用メモリ 80,024 KB
実行使用メモリ 550,008 KB
最終ジャッジ日時 2024-04-08 21:19:32
合計ジャッジ時間 12,598 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
63,740 KB
testcase_01 AC 146 ms
58,116 KB
testcase_02 AC 143 ms
58,088 KB
testcase_03 AC 143 ms
58,080 KB
testcase_04 AC 2,759 ms
262,156 KB
testcase_05 MLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
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 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Date;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();//m頂点の誘導部分グラフ
		int[] w=new int[n];
		for(int i=0;i<n;i++){
			w[i]=sc.nextInt();
		}
		long t=new Date().getTime();
		int inf=-1000000;
		System.err.println(new Date().getTime()-t+"ans");
		int[][][][] dp=new int[2][n+1][m+1][2];
		System.err.println(new Date().getTime()-t+"ans");
		//dp[0番目の頂点を拾ったかどうか0:拾わず/1:拾った][i番目まで確定][頂点数][i番目の頂点を拾ったか(0:拾わず/1:拾った)]=その時点での最大価値
		for(int i=0;i<2;i++){//2*n*k*l=2*6*3*2=72
			for(int l=0;l<2;l++){
				for(int k=0;k<=m;k++){
					for(int j=1;j<n;j++){
						dp[i][j][k][l]=inf;
					}
				}
			}
		}
		System.err.println(new Date().getTime()-t+"ams");
		dp[0][0][0][0]=0;
		dp[1][0][1][1]=0;
		dp[0][1][0][0]=0;
		dp[1][1][1][1]=0;
		for(int i=0;i<2;i++){
			for(int j=2;j<=n;j++){
				for(int k=0;k<=m;k++){
					for(int l=0;l<2;l++){
						if(l==0)
							dp[i][j][k][l]=Math.max(dp[i][j-1][k][0], dp[i][j-1][k][1]);
						if(l==1&&k>=1){
							dp[i][j][k][l]=Math.max(dp[i][j-1][k-1][0], dp[i][j-1][k-1][1]+w[j-2]);
						}
					}
				}
			}
		}
		int max;
		max=Math.max(dp[0][n][m][0],dp[0][n][m][1]);
		max=Math.max(dp[1][n][m][0],dp[1][n][m][1]+w[n-1]);
		System.out.println(max);
		System.err.println(new Date().getTime()-t+"ans");
	}
}
0