結果

問題 No.4 おもりと天秤
コンテスト
ユーザー shin
提出日時 2026-06-17 17:02:59
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
WA  
実行時間 -
コード長 925 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,391 ms
コンパイル使用メモリ 83,352 KB
実行使用メモリ 43,392 KB
最終ジャッジ日時 2026-06-17 17:03:09
合計ジャッジ時間 9,176 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.Arrays;
import java.util.Scanner;

public class No4 {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner((System.in));
		int N = scanner.nextInt() , i , sum = 0 , max = 0;
		
		Integer[] W = new Integer[N];
		for(i = 0;i < N;i++) {
			W[i] = scanner.nextInt();
			sum += W[i];
			max = Math.max(max, W[i]);
		}
		
		scanner.close();
		
		Arrays.sort(W);

		if(sum % 2 == 1 || max > sum / 2 ) {
			System.out.println("impossible");
		}else {
			if(calcWsum(0, W, sum / 2)){
				System.out.println("impossible");
			}else {
				System.out.println("possible");
			}
			
		}
	
	}
	
	public static boolean calcWsum(int j , Integer[] W , int nokori) {
		
		boolean result = false;
		
		if(W[j] > nokori) {
			result = false;
		}else if(W[j] == nokori) {
			result = true;
		}else {
			nokori = nokori - W[j];
			result = calcWsum(j+1, W, nokori - W[j]);
		}
		
		return result;
		
	}

}
0