結果

問題 No.4 おもりと天秤
ユーザー kenji_shioya
提出日時 2016-06-02 02:24:32
言語 Java
(openjdk 23)
結果
AC  
実行時間 156 ms / 5,000 ms
コード長 705 bytes
コンパイル時間 3,517 ms
コンパイル使用メモリ 74,388 KB
実行使用メモリ 55,968 KB
最終ジャッジ日時 2024-06-26 09:34:34
合計ジャッジ時間 7,721 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise45{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] weight = new int[n];
    int sum = 0;

    for (int i = 0; i < n; i++){
      int x = sc.nextInt();
      weight[i] = x;
      sum += x;
    }

    boolean[] dp = new boolean[sum + 1];
    dp[0] = true;

    for(int a = 0; a < n; a++){
      for(int b = sum; b >= 0; b--){
        if(dp[b] == true){
          //System.out.println(b);
          dp[b + weight[a]] = true;
        }
      }
    }

    if (sum % 2 == 1 || !dp[sum / 2]){
      System.out.println("impossible");
	   }else{
       System.out.println("possible");
     }
  }
}
0