結果

問題 No.4 おもりと天秤
コンテスト
ユーザー tenten
提出日時 2020-11-18 16:53:52
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 126 ms / 5,000 ms
コード長 674 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,741 ms
コンパイル使用メモリ 82,152 KB
実行使用メモリ 45,436 KB
最終ジャッジ日時 2026-04-03 13:35:12
合計ジャッジ時間 5,103 ms
ジャッジサーバーID
(参考情報)
judge5_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean[] isPossible = new boolean[n * 100 + 1];
        isPossible[0] = true;
        int total = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            total += x;
            for (int j = i * 100; j >= 0 ; j--) {
                isPossible[j + x] |= isPossible[j];
            }
        }
        if (total % 2 == 1 || !isPossible[total / 2]) { 
            System.out.println("impossible");
        } else {
            System.out.println("possible");
        }
    }
}
0