結果

問題 No.4 おもりと天秤
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-16 18:25:41
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,295 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 78,792 KB
実行使用メモリ 189,652 KB
最終ジャッジ日時 2023-09-17 20:54:29
合計ジャッジ時間 7,976 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,728 KB
testcase_01 AC 127 ms
55,708 KB
testcase_02 AC 129 ms
55,568 KB
testcase_03 AC 129 ms
55,888 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 124 ms
55,792 KB
testcase_07 WA -
testcase_08 AC 132 ms
55,732 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 128 ms
56,280 KB
testcase_12 AC 126 ms
55,852 KB
testcase_13 AC 127 ms
56,008 KB
testcase_14 AC 125 ms
56,180 KB
testcase_15 AC 129 ms
55,708 KB
testcase_16 AC 125 ms
55,952 KB
testcase_17 AC 131 ms
55,860 KB
testcase_18 AC 306 ms
114,740 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
   public static void main(String[] args) throws Exception {
       Scanner koko = new Scanner(System.in);
       int n = koko.nextInt();
       int total = 0;
       int[] w = new int[n];
       for(int i=0; i<n; i++){
           w[i]=koko.nextInt();
           total=total+w[i];
       }
       if(total%2!=0){
           System.out.println("impossible");
       }else{
           int h = total/2;
           boolean[][][] judge = new boolean[n][n][total];
           judge[0][0][0]=true;
           for(int i=0; i<n-1; i++){
               for(int j=0; j<n-1; j++){
                   for(int k=0; k<h; k++){
                       if(judge[i][j][k]){
                           judge[i+1][j][k]=true;
                           judge[i+1][j+1][k+w[i]]=true;
                       }
                   }
               }
           }
           boolean pos = false;
           for(int i=0; i<n; i++){
               for(int j=0; j<=i; j++){
                   if(judge[i][j][h]){
                       pos = true;
                       System.out.println("possible");
                       break;
                   }
               }
           }
           if(!pos){
               System.out.println("impossible");
           }
       }
    }
}
0