結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-05-20 17:06:18 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 30 ms / 5,000 ms | 
| コード長 | 803 bytes | 
| コンパイル時間 | 4,767 ms | 
| コンパイル使用メモリ | 110,184 KB | 
| 実行使用メモリ | 27,168 KB | 
| 最終ジャッジ日時 | 2024-06-26 10:17:33 | 
| 合計ジャッジ時間 | 4,221 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
    public static void Main() {
        string[] d = Console.ReadLine().Split(' ');
        int N = int.Parse(d[0]);
        var da = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        if (da.Sum(x => x) % 2 != 0) {
            Console.WriteLine("impossible");
            return;
        }
        int m = da.Sum(x => x) / 2;
        var dp = new bool[10000];
        dp[0] = true;
        for (int i = 0; i < N; i++) {
            for (int j = m; j >= da[i]; j--) {
                dp[j] |= dp[j - da[i]];
            }
        }
        if (dp[m]) {
            Console.WriteLine("possible");
        }
        else {
            Console.WriteLine("impossible");
        }
    }
}
            
            
            
        