結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-08-03 15:40:47 | 
| 言語 | C# (.NET 8.0.404) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,317 bytes | 
| コンパイル時間 | 10,087 ms | 
| コンパイル使用メモリ | 167,500 KB | 
| 実行使用メモリ | 187,680 KB | 
| 最終ジャッジ日時 | 2024-10-13 12:29:00 | 
| 合計ジャッジ時間 | 9,386 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 22 RE * 1 | 
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (87 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/
ソースコード
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");
                }
            }
        }
    }
}
            
            
            
        