結果

問題 No.4 おもりと天秤
コンテスト
ユーザー yuppe19 😺
提出日時 2015-04-21 22:04:44
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 78 ms / 5,000 ms
コード長 755 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,844 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 48,176 KB
最終ジャッジ日時 2026-03-13 01:34:05
合計ジャッジ時間 4,237 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;
import java.util.stream.*;

public class Main {
    private void solve() {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] ws = Stream.of(sc.nextLine().split(" "))
                              .mapToInt(Integer::parseInt)
                              .toArray();
        int sum = Arrays.stream(ws).sum();
        boolean[] ok = new boolean[sum+1];
        ok[0] = true;
        for(int w : ws) {
            for(int i=sum; i>=0; i--) {
                if(ok[i]) { ok[i+w] = true; }
            }
        }
        System.out.println(ok[sum/2] && sum%2==0 ? "possible" : "impossible");
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}
0