結果
| 問題 | 
                            No.4 おもりと天秤
                             | 
                    
| コンテスト | |
| ユーザー | 
                             fkwnw3_1243
                         | 
                    
| 提出日時 | 2017-05-07 23:14:41 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 80 ms / 5,000 ms | 
| コード長 | 1,353 bytes | 
| コンパイル時間 | 1,991 ms | 
| コンパイル使用メモリ | 77,440 KB | 
| 実行使用メモリ | 39,108 KB | 
| 最終ジャッジ日時 | 2024-06-26 10:16:02 | 
| 合計ジャッジ時間 | 4,265 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static java.lang.System.in;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int N = Integer.parseInt(reader.readLine());
        String[] inputs = reader.readLine().split(" ");
        int[] weights = new int[N];
        int sumOfWeights = 0;
        for (int i = 0; i < N; i++) {
            int weight = Integer.parseInt(inputs[i]);
            weights[i] = weight;
            sumOfWeights += weight;
        }
        if (sumOfWeights % 2 != 0) {
            System.out.println("impossible");
        } else {
            int requiredWeight = sumOfWeights / 2;
            boolean[][] dp = new boolean[101][10001];
            dp[0][0] = true;
            for (int i = 0; i < N; i++) {
                for (int j = 0; j <= 10000; j++) {
                    if (dp[i][j]) {
                        dp[i + 1][j + weights[i]] = true;
                        dp[i + 1][j] = true;
                    }
                }
            }
            if (dp[N][requiredWeight]) {
                System.out.println("possible");
            } else {
                System.out.println("impossible");
            }
        }
    }
}
            
            
            
        
            
fkwnw3_1243