結果

問題 No.4 おもりと天秤
ユーザー NoNo
提出日時 2015-06-21 19:38:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 1,608 bytes
コンパイル時間 2,256 ms
コンパイル使用メモリ 105,164 KB
実行使用メモリ 23,616 KB
最終ジャッジ日時 2023-09-08 16:19:36
合計ジャッジ時間 4,595 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
21,560 KB
testcase_01 AC 54 ms
21,440 KB
testcase_02 AC 57 ms
21,464 KB
testcase_03 AC 58 ms
21,500 KB
testcase_04 AC 57 ms
19,448 KB
testcase_05 AC 59 ms
21,508 KB
testcase_06 AC 56 ms
21,580 KB
testcase_07 AC 57 ms
23,616 KB
testcase_08 AC 55 ms
21,512 KB
testcase_09 AC 59 ms
23,492 KB
testcase_10 AC 58 ms
23,480 KB
testcase_11 AC 56 ms
23,548 KB
testcase_12 AC 56 ms
21,384 KB
testcase_13 AC 56 ms
23,556 KB
testcase_14 AC 56 ms
21,388 KB
testcase_15 AC 57 ms
21,396 KB
testcase_16 AC 58 ms
23,496 KB
testcase_17 AC 57 ms
21,444 KB
testcase_18 AC 58 ms
23,500 KB
testcase_19 AC 59 ms
21,516 KB
testcase_20 AC 59 ms
21,532 KB
testcase_21 AC 58 ms
21,436 KB
testcase_22 AC 60 ms
23,532 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;

namespace foryuki
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var w = ConvertStringArrayToIntArray(Console.ReadLine().Split());
            if (w.Sum() % 2 == 1)
            {
                Console.WriteLine("impossible");
                return;
            }
            int k = w.Sum();

            var d = new bool[k + 1];
            d[0] = true;
            for (int i = 1; i < d.Length; i++)
            {
                d[i] = false;
            }

            for (int i = 0; i < w.Length; i++)
            {
                for (int j = k; j >= 0; j--)
                {
                    if (d[j] == true)
                    {
                        d[j + w[i]] = true;
                    }
                }
            }

            if (d[k / 2])
            {
                Console.WriteLine("possible");
            }
            else
            {
                Console.WriteLine("impossible");
            }

        }

        //-------------------------------------------------------------

        static int[] ConvertStringArrayToIntArray(string[] array)
        {
            return Array.ConvertAll(array, str => int.Parse(str));
        }

        static List<int> ConvertStringArrayToIntList(string[] str)
        {
            var list = new List<int>();
            foreach (var c in str) list.Add(int.Parse(c));
            return list;
        }
    }
}
0