結果

問題 No.783 門松計画
ユーザー kuuso1kuuso1
提出日時 2019-01-11 22:47:58
言語 C#
(csc 3.9.0)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 2,334 bytes
コンパイル時間 2,195 ms
使用メモリ 15,488 KB
最終ジャッジ日時 2023-02-23 17:27:30
合計ジャッジ時間 5,052 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 54 ms
14,760 KB
testcase_01 AC 54 ms
14,748 KB
testcase_02 AC 55 ms
14,804 KB
testcase_03 AC 55 ms
14,920 KB
testcase_04 AC 55 ms
14,840 KB
testcase_05 AC 54 ms
14,724 KB
testcase_06 AC 55 ms
14,724 KB
testcase_07 AC 55 ms
14,748 KB
testcase_08 AC 55 ms
14,672 KB
testcase_09 AC 55 ms
14,844 KB
testcase_10 AC 63 ms
15,488 KB
testcase_11 AC 132 ms
15,340 KB
testcase_12 AC 84 ms
15,376 KB
testcase_13 AC 56 ms
14,868 KB
testcase_14 AC 58 ms
14,980 KB
testcase_15 AC 56 ms
14,888 KB
testcase_16 AC 55 ms
14,844 KB
testcase_17 AC 57 ms
14,948 KB
testcase_18 AC 55 ms
14,700 KB
testcase_19 AC 57 ms
15,092 KB
testcase_20 AC 55 ms
14,760 KB
testcase_21 AC 55 ms
14,716 KB
testcase_22 AC 55 ms
14,788 KB
testcase_23 AC 54 ms
14,808 KB
testcase_24 AC 56 ms
14,892 KB
testcase_25 AC 55 ms
14,796 KB
testcase_26 AC 56 ms
14,896 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][][];
		for(int i=0;i<N;i++){
			dp[i] = new int[N][];
			for(int j=0;j<N;j++){
				dp[i][j] = new int[C + 1];
				for(int k=0;k<=C;k++){
					dp[i][j][k] = -1;
				}
			}
		}
		
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				if(L[i] == L[j]) continue;
				if(W[i] + W[j] > C) continue;
				dp[i][j][W[i] + W[j]] = L[i] + L[j];
			}
		}
		//for(int i=0;i<N;i++) for(int j=0;j<N;j++) for(int c=0;c<=C;c++) if(dp[i][j][c] != -1) Console.WriteLine("{0} {1} {2} {3}",i,j,c,dp[i][j][c]);
		
		
		for(int c=0;c<C;c++){
			for(int i=0;i<N;i++){
				for(int j=0;j<N;j++){
					if(dp[i][j][c] == -1) continue;
					for(int k=0;k<N;k++){
						if(L[i] < L[j] && L[j] > L[k] && L[i] != L[k]){
							if(c + W[k] <= C){
								dp[j][k][c + W[k]] = Math.Max(dp[j][k][c + W[k]], dp[i][j][c] + L[k]);
							}
						}
						if(L[i] > L[j] && L[j] < L[k] && L[i] != L[k]){
							if(c + W[k] <= C){
								dp[j][k][c + W[k]] = Math.Max(dp[j][k][c + W[k]], dp[i][j][c] + L[k]);
							}
						}
						
					}
				}
			}
		}
		
		
		int max = 0;
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				for(int c=0;c<=C;c++){
					if(dp[i][j][c] == -1) continue;
					if(L[i] + L[j] == dp[i][j][c]) continue;
					//Console.WriteLine("{0} {1} {2} {3}",i,j,c,dp[i][j][c]);
					max = Math.Max(max, dp[i][j][c]);
				}
			}
		}
		Console.WriteLine(max);
	}
	int N,C;
	int[] L;
	int[] W;
	public Sol(){
		var d = ria();
		N = d[0]; C = d[1];
		L = ria();
		W = ria();
	}

	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(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0