結果

問題 No.4 おもりと天秤
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-16 18:24:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,353 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 84,852 KB
実行使用メモリ 190,492 KB
最終ジャッジ日時 2023-09-17 20:53:50
合計ジャッジ時間 9,073 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 127 ms
55,608 KB
testcase_02 AC 127 ms
55,844 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 123 ms
55,868 KB
testcase_07 WA -
testcase_08 AC 131 ms
55,936 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 121 ms
55,652 KB
testcase_12 AC 120 ms
55,960 KB
testcase_13 AC 122 ms
55,856 KB
testcase_14 AC 123 ms
56,068 KB
testcase_15 AC 123 ms
55,980 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 301 ms
115,140 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(i+" "+j+" "+h);
                       System.out.println("possible");
                       break;
                   }
               }
           }
           if(!pos){
               System.out.println("impossible");
           }
       }
    }
}
0