結果

問題 No.4 おもりと天秤
ユーザー 抹茶アイス抹茶アイス
提出日時 2023-08-03 15:40:47
言語 C#
(.NET 8.0.203)
結果
RE  
実行時間 -
コード長 1,317 bytes
コンパイル時間 17,625 ms
コンパイル使用メモリ 166,980 KB
実行使用メモリ 188,636 KB
最終ジャッジ日時 2024-04-21 13:48:11
合計ジャッジ時間 11,135 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
30,420 KB
testcase_01 AC 54 ms
30,320 KB
testcase_02 AC 55 ms
30,464 KB
testcase_03 AC 52 ms
30,720 KB
testcase_04 AC 55 ms
30,592 KB
testcase_05 AC 64 ms
31,872 KB
testcase_06 RE -
testcase_07 AC 64 ms
31,744 KB
testcase_08 AC 54 ms
30,592 KB
testcase_09 AC 67 ms
32,000 KB
testcase_10 AC 67 ms
32,000 KB
testcase_11 AC 52 ms
30,720 KB
testcase_12 AC 51 ms
30,448 KB
testcase_13 AC 49 ms
30,320 KB
testcase_14 AC 51 ms
30,720 KB
testcase_15 AC 50 ms
30,592 KB
testcase_16 AC 50 ms
30,848 KB
testcase_17 AC 50 ms
30,720 KB
testcase_18 AC 66 ms
32,128 KB
testcase_19 AC 65 ms
32,000 KB
testcase_20 AC 62 ms
31,992 KB
testcase_21 AC 62 ms
31,720 KB
testcase_22 AC 63 ms
188,636 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (105 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

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

namespace yukicoder
{
    public class Program
    {
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var w = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var k = w.Sum();
            var c = new bool[n, k / 2 + 1];
            c[0, 0] = true;
            c[0, w[0]] = true;
            if (k % 2 != 0)
            {
                Console.WriteLine("impossible");
            }
            else
            {
                for (var i = 1; i < n; i++)
                {
                    for(var j = 0; j <= k / 2 ; j++)
                    {
                        if (c[i - 1, j])
                        {
                            c[i, j] = true;
                            if (j + w[i] <= k / 2)
                            {
                                c[i, j + w[i]] = true;
                            }
                        }
                    }
                }
                if (c[n - 1, k / 2])
                {
                    Console.WriteLine("possible");
                }
                else
                {
                    Console.WriteLine("impossible");
                }
            }
        }
    }
}
0