結果

問題 No.4 おもりと天秤
ユーザー DAZYDAZY
提出日時 2017-05-23 01:16:16
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,085 bytes
コンパイル時間 4,627 ms
コンパイル使用メモリ 77,484 KB
実行使用メモリ 57,916 KB
最終ジャッジ日時 2023-10-19 14:27:49
合計ジャッジ時間 14,563 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
57,340 KB
testcase_01 AC 138 ms
57,624 KB
testcase_02 AC 128 ms
57,260 KB
testcase_03 AC 125 ms
57,572 KB
testcase_04 AC 136 ms
57,560 KB
testcase_05 AC 142 ms
57,784 KB
testcase_06 AC 130 ms
57,640 KB
testcase_07 AC 135 ms
57,508 KB
testcase_08 AC 139 ms
57,916 KB
testcase_09 AC 136 ms
57,528 KB
testcase_10 AC 133 ms
57,480 KB
testcase_11 AC 124 ms
57,532 KB
testcase_12 AC 110 ms
56,200 KB
testcase_13 AC 127 ms
57,292 KB
testcase_14 AC 125 ms
57,088 KB
testcase_15 AC 127 ms
57,488 KB
testcase_16 AC 124 ms
57,536 KB
testcase_17 AC 123 ms
57,468 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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");
    }
}
0