結果

問題 No.4 おもりと天秤
ユーザー CrazyBBBCrazyBBB
提出日時 2016-03-05 20:35:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 723 bytes
コンパイル時間 3,274 ms
コンパイル使用メモリ 74,256 KB
実行使用メモリ 57,752 KB
最終ジャッジ日時 2023-10-24 19:58:32
合計ジャッジ時間 6,479 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
57,404 KB
testcase_01 AC 130 ms
57,416 KB
testcase_02 AC 131 ms
57,380 KB
testcase_03 AC 130 ms
57,484 KB
testcase_04 AC 131 ms
57,340 KB
testcase_05 AC 146 ms
57,620 KB
testcase_06 AC 129 ms
57,656 KB
testcase_07 AC 146 ms
57,620 KB
testcase_08 AC 140 ms
57,324 KB
testcase_09 AC 150 ms
57,524 KB
testcase_10 AC 145 ms
57,752 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 130 ms
57,544 KB
testcase_14 WA -
testcase_15 AC 128 ms
57,344 KB
testcase_16 AC 127 ms
57,532 KB
testcase_17 AC 126 ms
57,232 KB
testcase_18 AC 148 ms
57,684 KB
testcase_19 AC 145 ms
57,720 KB
testcase_20 AC 143 ms
57,324 KB
testcase_21 AC 145 ms
57,660 KB
testcase_22 AC 145 ms
57,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	static boolean[] can;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] W = new int[N];
        int sum = 0;
		for (int i=0; i<N; i++) {
			W[i] = sc.nextInt();
			sum += W[i];
		}
		if (sum%2 != 0) {
			System.out.println("impossible");
		} else {
			can = new boolean[sum/2+1];
			can[0] = true;

			for (int i=0; i<N; i++) {
				for (int j=0; j<=sum/2; j++) {
					if (can[j] && j+W[i]<=sum/2) {
						can[j+W[i]] = true;
					}
				}
			}

			if (can[sum/2]) {
				System.out.println("possible");
			} else {
				System.out.println("impossible");
			}
		}

        sc.close();
    }
}
0