結果

問題 No.783 門松計画
ユーザー kuuso1kuuso1
提出日時 2019-01-11 22:47:58
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 2,334 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 105,628 KB
実行使用メモリ 22,872 KB
最終ジャッジ日時 2023-09-30 18:39:36
合計ジャッジ時間 5,121 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
20,756 KB
testcase_01 AC 58 ms
18,792 KB
testcase_02 AC 59 ms
22,776 KB
testcase_03 AC 60 ms
22,780 KB
testcase_04 AC 59 ms
20,704 KB
testcase_05 AC 59 ms
22,788 KB
testcase_06 AC 59 ms
22,868 KB
testcase_07 AC 59 ms
18,712 KB
testcase_08 AC 59 ms
18,660 KB
testcase_09 AC 59 ms
22,764 KB
testcase_10 AC 69 ms
20,832 KB
testcase_11 AC 141 ms
22,860 KB
testcase_12 AC 89 ms
22,872 KB
testcase_13 AC 61 ms
20,824 KB
testcase_14 AC 63 ms
22,840 KB
testcase_15 AC 60 ms
22,840 KB
testcase_16 AC 60 ms
20,808 KB
testcase_17 AC 59 ms
20,692 KB
testcase_18 AC 59 ms
20,836 KB
testcase_19 AC 61 ms
20,656 KB
testcase_20 AC 60 ms
22,772 KB
testcase_21 AC 60 ms
20,920 KB
testcase_22 AC 59 ms
20,796 KB
testcase_23 AC 58 ms
20,716 KB
testcase_24 AC 60 ms
20,720 KB
testcase_25 AC 59 ms
20,724 KB
testcase_26 AC 60 ms
20,836 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