結果

問題 No.4 おもりと天秤
ユーザー doyazaki012doyazaki012
提出日時 2015-05-26 14:53:04
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 813 bytes
コンパイル時間 2,200 ms
コンパイル使用メモリ 74,488 KB
実行使用メモリ 56,412 KB
最終ジャッジ日時 2023-09-20 13:28:53
合計ジャッジ時間 9,756 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,856 KB
testcase_01 AC 126 ms
55,528 KB
testcase_02 AC 130 ms
55,408 KB
testcase_03 AC 125 ms
56,412 KB
testcase_04 AC 129 ms
55,732 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){
			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