結果

問題 No.4 おもりと天秤
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-14 20:13:59
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 943 bytes
コンパイル時間 2,447 ms
コンパイル使用メモリ 73,836 KB
実行使用メモリ 56,764 KB
最終ジャッジ日時 2023-08-17 06:45:46
合計ジャッジ時間 6,894 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,796 KB
testcase_01 AC 126 ms
55,932 KB
testcase_02 AC 129 ms
55,952 KB
testcase_03 AC 127 ms
55,560 KB
testcase_04 AC 129 ms
55,772 KB
testcase_05 AC 150 ms
56,404 KB
testcase_06 AC 125 ms
55,808 KB
testcase_07 AC 160 ms
56,044 KB
testcase_08 AC 135 ms
55,948 KB
testcase_09 AC 153 ms
55,820 KB
testcase_10 AC 149 ms
56,064 KB
testcase_11 AC 125 ms
55,772 KB
testcase_12 RE -
testcase_13 AC 125 ms
55,520 KB
testcase_14 AC 125 ms
55,716 KB
testcase_15 AC 123 ms
55,524 KB
testcase_16 AC 123 ms
55,848 KB
testcase_17 AC 125 ms
55,564 KB
testcase_18 AC 155 ms
55,976 KB
testcase_19 AC 150 ms
56,036 KB
testcase_20 AC 149 ms
56,764 KB
testcase_21 AC 148 ms
56,276 KB
testcase_22 AC 152 ms
56,040 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+1][TW];
        PW[0][W[0]-1]=true;
        for(int i=0; i<N; i++){
            for(int j=0; j<HW; j++){
                if(PW[i][HW-1-j]==true){
                    PW[i+1][HW-1-j+W[i]]=true;
                    PW[i+1][HW-1-j]=true;
                }
                if(PW[i+1][HW-1]==true){
                    System.out.println("possible");
                    return;
                }
            }
        }
        System.out.println("impossible");
    }
}
0