結果

問題 No.4 おもりと天秤
ユーザー k3079kk3079k
提出日時 2019-09-14 14:17:43
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 68 ms / 5,000 ms
コード長 1,084 bytes
コンパイル時間 1,080 ms
コンパイル使用メモリ 66,040 KB
実行使用メモリ 23,808 KB
最終ジャッジ日時 2023-09-20 02:02:28
合計ジャッジ時間 4,296 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
21,584 KB
testcase_01 AC 60 ms
21,612 KB
testcase_02 AC 64 ms
21,676 KB
testcase_03 AC 63 ms
23,708 KB
testcase_04 AC 62 ms
21,608 KB
testcase_05 AC 64 ms
23,788 KB
testcase_06 AC 62 ms
21,588 KB
testcase_07 AC 65 ms
19,596 KB
testcase_08 AC 59 ms
21,724 KB
testcase_09 AC 68 ms
23,728 KB
testcase_10 AC 67 ms
21,636 KB
testcase_11 AC 63 ms
21,768 KB
testcase_12 AC 63 ms
21,764 KB
testcase_13 AC 62 ms
21,640 KB
testcase_14 AC 64 ms
21,728 KB
testcase_15 AC 64 ms
23,792 KB
testcase_16 AC 64 ms
23,684 KB
testcase_17 AC 63 ms
21,792 KB
testcase_18 AC 64 ms
21,760 KB
testcase_19 AC 64 ms
23,656 KB
testcase_20 AC 64 ms
23,808 KB
testcase_21 AC 64 ms
19,724 KB
testcase_22 AC 64 ms
21,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

namespace Test01
{
    class Program
    {
        
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');

            int[] w = new int[N + 1];
            for(int i = 1; i <= N; i++)
            {
                w[i] = int.Parse(input[i - 1]);
            }

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

            int max = sum / 2;
            bool[] dp = new bool[max + 1];

            dp[0] = true;
            w = w.OrderBy(x => x).ToArray();
            for(int i = 1; i <= N; i++)
            {
                for(int j = max; j >= 0; j--)
                {
                    if (w[i] + j <= max) dp[w[i] + j] |= dp[j];
                }
            }

            if (dp[max]) Console.WriteLine("possible");
            else Console.WriteLine("impossible");
        }
    }
}
0