結果

問題 No.4 おもりと天秤
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-14 20:23:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 154 ms / 5,000 ms
コード長 939 bytes
コンパイル時間 1,951 ms
コンパイル使用メモリ 74,500 KB
実行使用メモリ 56,632 KB
最終ジャッジ日時 2023-09-08 17:14:36
合計ジャッジ時間 6,128 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
56,020 KB
testcase_01 AC 121 ms
56,136 KB
testcase_02 AC 119 ms
55,644 KB
testcase_03 AC 120 ms
56,020 KB
testcase_04 AC 125 ms
56,048 KB
testcase_05 AC 154 ms
56,196 KB
testcase_06 AC 118 ms
56,016 KB
testcase_07 AC 147 ms
55,964 KB
testcase_08 AC 129 ms
56,020 KB
testcase_09 AC 147 ms
55,892 KB
testcase_10 AC 145 ms
56,100 KB
testcase_11 AC 122 ms
55,656 KB
testcase_12 AC 119 ms
55,744 KB
testcase_13 AC 122 ms
56,172 KB
testcase_14 AC 119 ms
55,704 KB
testcase_15 AC 117 ms
55,772 KB
testcase_16 AC 119 ms
56,284 KB
testcase_17 AC 122 ms
56,480 KB
testcase_18 AC 149 ms
56,408 KB
testcase_19 AC 147 ms
55,972 KB
testcase_20 AC 148 ms
56,156 KB
testcase_21 AC 147 ms
56,112 KB
testcase_22 AC 151 ms
56,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] W = new int [N];
        int TW = 0;
        for(int i=0; i<N; i++){
            W[i] = sc.nextInt();
            TW = TW + W[i];
        }
        if(TW%2==1){
            System.out.println("impossible");
            return;
        }
        int HW = TW/2;
        boolean [][] PW = new boolean [N+2][TW];
        PW[0][W[0]-1]=true;
        for(int i=1; i<N; i++){
            for(int j=0; j<HW; j++){
                if(PW[i-1][HW-1-j]==true){
                    PW[i][HW-1-j+W[i]]=true;
                    PW[i][HW-1-j]=true;
                }
                if(PW[i][HW-1]==true){
                    System.out.println("possible");
                    return;
                }
            }
        }
        System.out.println("impossible");
    }
}
0