結果

問題 No.4 おもりと天秤
ユーザー HimatsubushinHimatsubushin
提出日時 2019-12-21 14:53:20
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 1,145 bytes
コンパイル時間 2,642 ms
コンパイル使用メモリ 67,864 KB
実行使用メモリ 24,048 KB
最終ジャッジ日時 2023-09-26 15:12:24
合計ジャッジ時間 3,734 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
21,604 KB
testcase_01 AC 57 ms
21,848 KB
testcase_02 AC 60 ms
23,736 KB
testcase_03 AC 58 ms
23,752 KB
testcase_04 AC 57 ms
23,624 KB
testcase_05 AC 59 ms
21,636 KB
testcase_06 AC 56 ms
21,572 KB
testcase_07 AC 64 ms
23,644 KB
testcase_08 AC 60 ms
21,584 KB
testcase_09 AC 64 ms
24,048 KB
testcase_10 AC 61 ms
23,772 KB
testcase_11 AC 57 ms
21,656 KB
testcase_12 AC 58 ms
21,580 KB
testcase_13 AC 59 ms
23,644 KB
testcase_14 AC 59 ms
23,684 KB
testcase_15 AC 58 ms
23,672 KB
testcase_16 AC 58 ms
21,700 KB
testcase_17 AC 57 ms
21,668 KB
testcase_18 AC 61 ms
23,692 KB
testcase_19 AC 64 ms
23,704 KB
testcase_20 AC 61 ms
21,596 KB
testcase_21 AC 60 ms
19,596 KB
testcase_22 AC 60 ms
21,644 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