結果

問題 No.4 おもりと天秤
ユーザー vektor_dnchrvektor_dnchr
提出日時 2016-11-07 19:44:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 170 ms / 5,000 ms
コード長 1,063 bytes
コンパイル時間 2,284 ms
コンパイル使用メモリ 73,844 KB
実行使用メモリ 57,656 KB
最終ジャッジ日時 2023-09-08 17:14:18
合計ジャッジ時間 7,222 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
56,492 KB
testcase_01 AC 154 ms
55,992 KB
testcase_02 AC 149 ms
56,040 KB
testcase_03 AC 155 ms
56,284 KB
testcase_04 AC 147 ms
56,172 KB
testcase_05 AC 163 ms
55,972 KB
testcase_06 AC 152 ms
56,320 KB
testcase_07 AC 165 ms
56,164 KB
testcase_08 AC 162 ms
57,656 KB
testcase_09 AC 170 ms
56,280 KB
testcase_10 AC 169 ms
56,272 KB
testcase_11 AC 154 ms
56,324 KB
testcase_12 AC 146 ms
55,932 KB
testcase_13 AC 146 ms
56,016 KB
testcase_14 AC 147 ms
56,020 KB
testcase_15 AC 154 ms
56,232 KB
testcase_16 AC 152 ms
55,908 KB
testcase_17 AC 154 ms
56,424 KB
testcase_18 AC 161 ms
56,412 KB
testcase_19 AC 166 ms
56,292 KB
testcase_20 AC 163 ms
55,944 KB
testcase_21 AC 169 ms
56,376 KB
testcase_22 AC 162 ms
56,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] W = new int[100];
        boolean[][] dp = new boolean[101][10001];
        int sum = 0;
        
        for(int i=0; i<101; i++)
            for(int j=0; j<10001; j++)
                dp[i][j] = false;
        
        for(int i=0; i<N; i++){
            W[i] = sc.nextInt();
            sum += W[i];
        }
        
        if(sum%2 == 1) System.out.println("impossible ");
        else{
            dp[0][0] = true;
            for(int i=0; i<N; i++){
                for(int j=0; j<=10000; j++){
                    if(dp[i][j] == true){
                        dp[i+1][j+W[i]] = true;
                        dp[i+1][j] = true;
                    }
                }
            }
            
            if(dp[N][sum/2] == true) System.out.println("possible");
            else System.out.println("impossible ");
        }
    }
}
0