結果

問題 No.4 おもりと天秤
ユーザー CrazyBBBCrazyBBB
提出日時 2016-03-05 20:37:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 153 ms / 5,000 ms
コード長 723 bytes
コンパイル時間 6,660 ms
コンパイル使用メモリ 71,200 KB
実行使用メモリ 56,328 KB
最終ジャッジ日時 2023-09-08 16:36:43
合計ジャッジ時間 6,731 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,708 KB
testcase_01 AC 121 ms
55,736 KB
testcase_02 AC 121 ms
55,732 KB
testcase_03 AC 122 ms
55,748 KB
testcase_04 AC 121 ms
55,856 KB
testcase_05 AC 142 ms
55,640 KB
testcase_06 AC 119 ms
55,596 KB
testcase_07 AC 141 ms
55,780 KB
testcase_08 AC 132 ms
56,096 KB
testcase_09 AC 141 ms
55,916 KB
testcase_10 AC 148 ms
53,732 KB
testcase_11 AC 120 ms
55,616 KB
testcase_12 AC 121 ms
55,524 KB
testcase_13 AC 121 ms
55,764 KB
testcase_14 AC 120 ms
55,860 KB
testcase_15 AC 123 ms
55,780 KB
testcase_16 AC 128 ms
55,796 KB
testcase_17 AC 122 ms
55,960 KB
testcase_18 AC 152 ms
55,688 KB
testcase_19 AC 139 ms
56,328 KB
testcase_20 AC 139 ms
56,212 KB
testcase_21 AC 140 ms
55,740 KB
testcase_22 AC 153 ms
55,840 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=sum/2; j>=0; 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