結果

問題 No.4 おもりと天秤
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-14 17:19:27
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 871 bytes
コンパイル時間 2,474 ms
コンパイル使用メモリ 71,372 KB
実行使用メモリ 56,372 KB
最終ジャッジ日時 2023-08-17 06:44:30
合計ジャッジ時間 6,311 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
56,152 KB
testcase_01 AC 114 ms
55,856 KB
testcase_02 AC 117 ms
56,180 KB
testcase_03 AC 113 ms
56,000 KB
testcase_04 AC 115 ms
56,116 KB
testcase_05 AC 136 ms
55,988 KB
testcase_06 AC 115 ms
56,144 KB
testcase_07 AC 130 ms
55,776 KB
testcase_08 AC 122 ms
56,128 KB
testcase_09 AC 133 ms
56,216 KB
testcase_10 AC 133 ms
55,832 KB
testcase_11 WA -
testcase_12 AC 110 ms
55,800 KB
testcase_13 AC 113 ms
55,832 KB
testcase_14 AC 111 ms
56,028 KB
testcase_15 AC 115 ms
55,800 KB
testcase_16 AC 113 ms
55,724 KB
testcase_17 AC 112 ms
53,636 KB
testcase_18 AC 139 ms
55,844 KB
testcase_19 AC 134 ms
56,128 KB
testcase_20 AC 132 ms
56,240 KB
testcase_21 AC 135 ms
56,372 KB
testcase_22 AC 134 ms
55,816 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;
        int [] PW = new int [HW];
        for(int i=0; i<N; i++){
            for(int j=0; j<HW; j++){
                if( PW[HW-1-j]+W[i]<=HW ){
                    PW[ PW[HW-1-j]+W[i]-1 ] = PW[HW-1-j]+W[i];
                }
                if( PW[HW-1]==HW ){
                    System.out.println("possible");
                    return;
                }
            }
        }
        System.out.println("impossible");
    }
}
0