結果

問題 No.4 おもりと天秤
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-16 18:27:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 433 ms / 5,000 ms
コード長 1,302 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 73,944 KB
実行使用メモリ 189,832 KB
最終ジャッジ日時 2023-09-08 16:14:31
合計ジャッジ時間 8,101 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,908 KB
testcase_01 AC 122 ms
55,504 KB
testcase_02 AC 127 ms
55,968 KB
testcase_03 AC 123 ms
55,924 KB
testcase_04 AC 128 ms
55,672 KB
testcase_05 AC 358 ms
115,136 KB
testcase_06 AC 125 ms
55,572 KB
testcase_07 AC 316 ms
112,620 KB
testcase_08 AC 136 ms
55,944 KB
testcase_09 AC 433 ms
189,832 KB
testcase_10 AC 341 ms
131,236 KB
testcase_11 AC 123 ms
55,908 KB
testcase_12 AC 122 ms
56,124 KB
testcase_13 AC 127 ms
55,948 KB
testcase_14 AC 122 ms
55,544 KB
testcase_15 AC 122 ms
55,736 KB
testcase_16 AC 122 ms
55,896 KB
testcase_17 AC 120 ms
55,944 KB
testcase_18 AC 297 ms
114,572 KB
testcase_19 AC 301 ms
114,980 KB
testcase_20 AC 299 ms
115,124 KB
testcase_21 AC 276 ms
115,080 KB
testcase_22 AC 295 ms
114,664 KB
権限があれば一括ダウンロードができます

ソースコード

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;
    loop1:  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 loop1;
                   }
               }
           }
           if(!pos){
               System.out.println("impossible");
           }
       }
    }
}
0