結果

問題 No.4 おもりと天秤
ユーザー masaktmasakt
提出日時 2017-04-16 02:28:43
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,446 bytes
コンパイル時間 4,720 ms
コンパイル使用メモリ 105,232 KB
実行使用メモリ 30,536 KB
最終ジャッジ日時 2023-09-26 02:09:04
合計ジャッジ時間 10,474 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 57 ms
23,444 KB
testcase_02 AC 59 ms
21,484 KB
testcase_03 WA -
testcase_04 AC 59 ms
21,420 KB
testcase_05 AC 60 ms
23,480 KB
testcase_06 AC 59 ms
23,508 KB
testcase_07 AC 62 ms
21,448 KB
testcase_08 AC 56 ms
23,496 KB
testcase_09 AC 59 ms
21,444 KB
testcase_10 AC 61 ms
23,492 KB
testcase_11 AC 59 ms
23,472 KB
testcase_12 AC 58 ms
21,476 KB
testcase_13 AC 58 ms
21,440 KB
testcase_14 AC 59 ms
21,412 KB
testcase_15 AC 60 ms
23,336 KB
testcase_16 AC 58 ms
19,468 KB
testcase_17 WA -
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

class P
{
    static int[] w;
    static bool[][] dp;
    static bool dfs(int i, int j, int n, int sum, int goal)
    {
        bool ret = false;
        if (dp[i][j])
        {
            return dp[i][j];
        }
        if (goal == sum)
        {
            ret = true;
        }
        else if (goal < sum || j >= n - 1)
        {
            ret = false;
        }
        else
        {
            ret = dfs(j, j + 1, n, sum + w[j], goal) || dfs(j, j + 1, n, sum, goal);
        }
        return dp[i][j] = ret;
    }
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string[] _ = new string[n];
        _ = Console.ReadLine().Split(' ');
        n = _.Length;
        dp = new bool[n][];
        w = new int[n];
        int sum = 0;
        string ans = "";
        for (int i = 0; i < _.Length; i++)
        {
            dp[i] = new bool[n];
            w[i] = int.Parse(_[i]);
            sum += w[i];
        }

        if (sum % 2 == 0)
        {
            sum /= 2;
            Array.Sort(w);
            if (sum >= w.Last())
            {
                ans = dfs(0, 1, n, 0, sum) ? "possible" : "impossible";
            }
            else
            {
                ans = "impossible";
            }
        }
        else
        {
            ans = "impossible";
        }

        Console.WriteLine(ans);
    }
}

0