結果

問題 No.4 おもりと天秤
ユーザー HimatsubushinHimatsubushin
提出日時 2019-12-21 14:53:56
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 1,145 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 65,788 KB
実行使用メモリ 23,656 KB
最終ジャッジ日時 2023-09-26 15:14:27
合計ジャッジ時間 3,621 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
19,568 KB
testcase_01 AC 57 ms
21,600 KB
testcase_02 AC 58 ms
21,624 KB
testcase_03 AC 57 ms
23,656 KB
testcase_04 AC 57 ms
21,716 KB
testcase_05 AC 61 ms
21,700 KB
testcase_06 AC 57 ms
21,592 KB
testcase_07 AC 63 ms
23,592 KB
testcase_08 AC 57 ms
21,592 KB
testcase_09 AC 60 ms
21,988 KB
testcase_10 AC 61 ms
23,640 KB
testcase_11 AC 59 ms
21,608 KB
testcase_12 AC 61 ms
23,624 KB
testcase_13 AC 59 ms
21,688 KB
testcase_14 AC 59 ms
21,632 KB
testcase_15 AC 59 ms
21,720 KB
testcase_16 AC 58 ms
21,636 KB
testcase_17 AC 58 ms
19,712 KB
testcase_18 AC 61 ms
21,596 KB
testcase_19 AC 59 ms
21,700 KB
testcase_20 AC 60 ms
21,592 KB
testcase_21 AC 60 ms
21,576 KB
testcase_22 AC 61 ms
19,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Linq;

namespace No004_おもりと天秤
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int[] list = input.Select(int.Parse).ToArray();
            int sum = list.Sum();
            bool[,] dp = new bool[101, sum + 1];

            if (sum % 2 == 1)
            {
                Console.WriteLine("impossible");
            }
            else
            {
                dp[0, 0] = true;

                for (int i = 0; i < list.Length; i++)
                {
                    for (int j = 0; j <= sum; j++)
                    {
                        if (dp[i, j])
                        {
                            dp[i + 1, j + list[i]] = true;
                            dp[i + 1, j] = true;
                        }
                    }
                }

                if (dp[list.Length, sum / 2])
                    Console.WriteLine("possible");
                else
                    Console.WriteLine("impossible");
            }
        }
    }
}
0