結果

問題 No.4 おもりと天秤
ユーザー HimatsubushinHimatsubushin
提出日時 2019-12-21 11:57:09
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 1,115 bytes
コンパイル時間 1,957 ms
コンパイル使用メモリ 63,812 KB
実行使用メモリ 24,064 KB
最終ジャッジ日時 2023-09-26 10:34:41
合計ジャッジ時間 4,372 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
22,036 KB
testcase_01 AC 60 ms
21,988 KB
testcase_02 AC 60 ms
22,008 KB
testcase_03 AC 61 ms
21,932 KB
testcase_04 AC 62 ms
22,032 KB
testcase_05 AC 64 ms
19,992 KB
testcase_06 AC 60 ms
22,144 KB
testcase_07 AC 63 ms
22,088 KB
testcase_08 AC 60 ms
24,044 KB
testcase_09 AC 63 ms
21,984 KB
testcase_10 AC 64 ms
23,996 KB
testcase_11 AC 61 ms
21,984 KB
testcase_12 AC 60 ms
21,920 KB
testcase_13 AC 61 ms
24,064 KB
testcase_14 AC 60 ms
21,976 KB
testcase_15 AC 61 ms
22,008 KB
testcase_16 AC 61 ms
21,980 KB
testcase_17 AC 61 ms
24,024 KB
testcase_18 AC 63 ms
22,092 KB
testcase_19 AC 65 ms
19,904 KB
testcase_20 AC 67 ms
22,088 KB
testcase_21 AC 64 ms
22,100 KB
testcase_22 AC 64 ms
23,984 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();
            int[,] a = new int[3, 6];
            bool[,] dp = new bool[101, 10001];

            if (sum % 2 == 1)
            {
                Console.WriteLine("impossible");
                return;
            }

            dp[0, 0] = true;

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

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