結果

問題 No.107 モンスター
ユーザー kuuso1kuuso1
提出日時 2014-12-19 00:42:23
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 1,900 bytes
コンパイル時間 3,160 ms
コンパイル使用メモリ 105,780 KB
実行使用メモリ 31,904 KB
最終ジャッジ日時 2023-08-22 22:22:39
合計ジャッジ時間 5,658 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
22,880 KB
testcase_01 AC 57 ms
22,676 KB
testcase_02 AC 57 ms
18,568 KB
testcase_03 AC 58 ms
20,724 KB
testcase_04 AC 57 ms
20,616 KB
testcase_05 AC 57 ms
20,620 KB
testcase_06 AC 57 ms
20,796 KB
testcase_07 AC 57 ms
20,632 KB
testcase_08 AC 58 ms
20,524 KB
testcase_09 AC 58 ms
22,660 KB
testcase_10 AC 58 ms
22,640 KB
testcase_11 AC 57 ms
20,588 KB
testcase_12 AC 57 ms
18,744 KB
testcase_13 AC 63 ms
20,628 KB
testcase_14 AC 66 ms
22,700 KB
testcase_15 AC 66 ms
22,708 KB
testcase_16 AC 58 ms
20,644 KB
testcase_17 AC 59 ms
22,688 KB
testcase_18 AC 74 ms
27,860 KB
testcase_19 AC 74 ms
29,904 KB
testcase_20 AC 62 ms
20,656 KB
testcase_21 AC 61 ms
18,544 KB
testcase_22 AC 68 ms
22,776 KB
testcase_23 AC 78 ms
27,900 KB
testcase_24 AC 81 ms
31,904 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;
 
class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[][] dp=new int[1<<N][];
		for(int i=0;i<(1<<N);i++){
			dp[i]=new int[N+1];
		}
		
		for(int i=0;i<N;i++){
			if(D[i]>0){
				dp[1<<i][1]=100;
			}
			if(D[i]<0 && D[i]+100>0){
				dp[1<<i][1]=100+D[i];
			}
		}
//for(int ii=0;ii<(1<<N);ii++)Console.Write("{0} ",dp[ii][1]);Console.WriteLine();
		mask=0;
		for(int i=0;i<N;i++){
			if(D[i]<0)mask|=(1<<i);
		}
		
		int ns,nv;
		for(int i=1;i<N;i++){
			for(int s=1;s<(1<<N);s++){
				if(dp[s][i]==0)continue;
				for(int j=0;j<N;j++){
					if((s&(1<<j))==0){
						ns=s|(1<<j);
						if(D[j]>0){
							nv=Math.Min(dp[s][i]+D[j],maxHP(s));
							dp[ns][i+1]=Math.Max(dp[ns][i+1],nv);
						}
						if(D[j]<0 && D[j]+dp[s][i]>0){
							nv=D[j]+dp[s][i];
							dp[ns][i+1]=Math.Max(dp[ns][i+1],nv);
						}
					}
				}
			}
//for(int ii=0;ii<(1<<N);ii++)Console.Write("{0} ",dp[ii][i+1]);Console.WriteLine();
		}
		
		Console.WriteLine(dp[(1<<N)-1][N]);
		
		
		
	}
	
	int mask;
	int maxHP(int state){
		int ret=100;
		state&=mask;
		for(int i=0;i<N;i++){
			if((state&(1<<i))>0)ret+=100;
		}
		return ret;
	}
	
	
	int N;
	int[] D;
	public Sol(){
		N=ri();
		D=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(){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