結果

問題 No.4 おもりと天秤
ユーザー uafr_csuafr_cs
提出日時 2015-05-29 02:34:44
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 986 bytes
コンパイル時間 3,612 ms
コンパイル使用メモリ 75,772 KB
実行使用メモリ 56,220 KB
最終ジャッジ日時 2023-09-20 15:09:02
合計ジャッジ時間 8,073 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 128 ms
55,452 KB
testcase_02 AC 130 ms
55,460 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 129 ms
55,932 KB
testcase_07 WA -
testcase_08 AC 138 ms
55,732 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 129 ms
55,872 KB
testcase_12 AC 129 ms
55,980 KB
testcase_13 AC 129 ms
55,744 KB
testcase_14 AC 130 ms
55,968 KB
testcase_15 AC 128 ms
55,804 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 139 ms
55,704 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	
	public static boolean dfs(int deep, int N, int purpose, int current, boolean[] used){
		if(purpose == current){
			return true;
		}else if(purpose > current){
			return false;
		}else if(deep >= N){
			return false;
		}
		
		for(int i = deep; i < N; i++){
			if(!used[i]){
				used[i] = true;
				if(dfs(deep + 1, N, purpose, current, used)){
					return true;
				}
				used[i] = false;
			}
		}
		
		return false;
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		
		int[] arr = new int[N];
		for(int i = 0; i < N; i++){
			arr[i] = -sc.nextInt();
		}
		Arrays.sort(arr);
		for(int i = 0; i < N; i++){
			arr[i] = -arr[i];
		}
		
		final int purpose = Arrays.stream(arr).sum() / 2;
		
		System.out.println(dfs(0, N, purpose, 0, new boolean[N]) ? "possible" : "impossible");
		
		
	}
	
}
0