結果

問題 No.4 おもりと天秤
ユーザー mbanmban
提出日時 2016-10-31 14:59:14
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 63 ms / 5,000 ms
コード長 874 bytes
コンパイル時間 4,780 ms
コンパイル使用メモリ 103,728 KB
実行使用メモリ 23,780 KB
最終ジャッジ日時 2023-09-08 17:13:20
合計ジャッジ時間 5,486 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
23,720 KB
testcase_01 AC 59 ms
21,692 KB
testcase_02 AC 59 ms
21,600 KB
testcase_03 AC 60 ms
21,592 KB
testcase_04 AC 60 ms
23,724 KB
testcase_05 AC 62 ms
19,728 KB
testcase_06 AC 60 ms
21,700 KB
testcase_07 AC 62 ms
23,696 KB
testcase_08 AC 61 ms
23,672 KB
testcase_09 AC 63 ms
21,704 KB
testcase_10 AC 63 ms
23,716 KB
testcase_11 AC 60 ms
21,716 KB
testcase_12 AC 62 ms
21,784 KB
testcase_13 AC 59 ms
21,668 KB
testcase_14 AC 60 ms
21,768 KB
testcase_15 AC 61 ms
21,804 KB
testcase_16 AC 62 ms
23,768 KB
testcase_17 AC 60 ms
21,592 KB
testcase_18 AC 63 ms
21,604 KB
testcase_19 AC 62 ms
21,636 KB
testcase_20 AC 62 ms
21,780 KB
testcase_21 AC 62 ms
23,656 KB
testcase_22 AC 61 ms
23,780 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Magatro
{

    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] w = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        if (w.Sum() % 2 == 1)
        {
            Console.WriteLine("impossible");
            return;
        }
        int sum = w.Sum();
        int ans = w.Sum() / 2;
        bool[] dp = new bool[sum+1];
        dp[0] = true;
        for(int i = 0; i < N; i++)
        {
            for(int j = sum - w[i]; j >= 0; j--)
            {
                dp[j + w[i]] |= dp[j];

            }
        }
        if (dp[ans])
        {
            Console.WriteLine("possible");
        }
        else
        {
            Console.WriteLine("impossible");
        }
    }

 
}


0