結果
| 問題 |
No.4 おもりと天秤
|
| ユーザー |
DAZY
|
| 提出日時 | 2017-05-22 19:40:50 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,085 bytes |
| コンパイル時間 | 3,111 ms |
| コンパイル使用メモリ | 77,556 KB |
| 実行使用メモリ | 60,780 KB |
| 最終ジャッジ日時 | 2024-09-19 10:20:10 |
| 合計ジャッジ時間 | 12,328 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 TLE * 1 -- * 4 |
ソースコード
import java.util.Scanner;
public class No4 {
public static boolean check (int half, int[] W, int i, boolean b) {
if (i > 0) {
i--;
for (int j = i; j >= 0; j--) {
if (b) break;
if (half >= W[j]) {
if (half - W[j] == 0) b = true;
else b = check(half - W[j], W, j, b);
}
}
}
return b;
}
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int W[] = new int[N];
int sum = 0; int half;
boolean b = false;
for (int i = 0; i < N; i++) {
W[i] = scan.nextInt();
sum += W[i];
}
//合計が奇数なら2等分することはできない
if (sum % 2 != 0) {
System.out.println("impossible");
System.exit(0);
}
half = sum/2;
if (check(half, W, N, b)) System.out.println("possible");
else System.out.println("impossible");
}
}
DAZY