結果
| 問題 | No.4 おもりと天秤 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-06-17 17:01:37 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 924 bytes |
| 記録 | |
| コンパイル時間 | 4,770 ms |
| コンパイル使用メモリ | 83,592 KB |
| 実行使用メモリ | 42,752 KB |
| 最終ジャッジ日時 | 2026-06-17 17:01:50 |
| 合計ジャッジ時間 | 10,575 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 WA * 6 |
ソースコード
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 false;
}
}