結果

問題 No.4 おもりと天秤
ユーザー doyazaki012doyazaki012
提出日時 2015-05-26 16:03:35
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 842 bytes
コンパイル時間 3,631 ms
コンパイル使用メモリ 73,180 KB
実行使用メモリ 56,112 KB
最終ジャッジ日時 2023-09-20 13:29:48
合計ジャッジ時間 9,779 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,112 KB
testcase_01 AC 126 ms
55,768 KB
testcase_02 AC 132 ms
55,516 KB
testcase_03 AC 128 ms
55,432 KB
testcase_04 AC 130 ms
55,624 KB
testcase_05 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Yuki4{


	static boolean myFullSearch(int[] w,int count,int sum,int n,int purpose) {
		boolean left=false,right=false;
		
		
		sum += w[count];
		if(sum*2 == purpose){
			return true;
		}else if(count < n){
			if(sum*2<=purpose)
				left = myFullSearch(w,count+1,sum,n,purpose);
			right = myFullSearch(w,count+1,sum-w[count],n,purpose);
			if(left==true || right ==true) return true;
		}

		return false;
	}


	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] weight = new int[n+1];
		int sum=0;
		for(int i=0;i<n;i++){
			weight[i] = stdIn.nextInt();
			sum += weight[i];
		}

		boolean answer = myFullSearch(weight,0,0,n,sum);
		String a;
		if(answer==true){
			a="possible";
		}
		else{
			a="impossible";
		}
		System.out.println(a);




	}
}
0