結果

問題 No.4 おもりと天秤
ユーザー kohaku_kohaku
提出日時 2016-11-14 20:13:59
言語 Java
(openjdk 23)
結果
RE  
実行時間 -
コード長 943 bytes
コンパイル時間 2,033 ms
コンパイル使用メモリ 77,624 KB
実行使用メモリ 42,300 KB
最終ジャッジ日時 2024-11-26 01:18:30
合計ジャッジ時間 6,060 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 RE * 1
権限があれば一括ダウンロードができます

ソースコード

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