結果

問題 No.4 おもりと天秤
ユーザー CrazyBBB
提出日時 2016-03-05 20:35:16
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 723 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 74,780 KB
実行使用メモリ 54,440 KB
最終ジャッジ日時 2024-09-24 14:28:28
合計ジャッジ時間 6,429 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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