結果

問題 No.4 おもりと天秤
ユーザー kenji_shioyakenji_shioya
提出日時 2016-06-02 02:24:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 5,000 ms
コード長 705 bytes
コンパイル時間 3,105 ms
コンパイル使用メモリ 72,044 KB
実行使用メモリ 56,036 KB
最終ジャッジ日時 2023-09-08 16:45:14
合計ジャッジ時間 7,134 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,688 KB
testcase_01 AC 122 ms
55,976 KB
testcase_02 AC 124 ms
55,920 KB
testcase_03 AC 122 ms
55,516 KB
testcase_04 AC 123 ms
55,940 KB
testcase_05 AC 137 ms
55,744 KB
testcase_06 AC 122 ms
55,360 KB
testcase_07 AC 136 ms
55,616 KB
testcase_08 AC 132 ms
55,652 KB
testcase_09 AC 139 ms
55,660 KB
testcase_10 AC 140 ms
55,936 KB
testcase_11 AC 122 ms
56,036 KB
testcase_12 AC 123 ms
55,588 KB
testcase_13 AC 122 ms
55,916 KB
testcase_14 AC 122 ms
55,924 KB
testcase_15 AC 126 ms
55,408 KB
testcase_16 AC 123 ms
55,724 KB
testcase_17 AC 120 ms
55,520 KB
testcase_18 AC 138 ms
55,900 KB
testcase_19 AC 139 ms
55,656 KB
testcase_20 AC 139 ms
55,676 KB
testcase_21 AC 136 ms
55,760 KB
testcase_22 AC 140 ms
55,780 KB
権限があれば一括ダウンロードができます

ソースコード

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