結果

問題 No.4 おもりと天秤
ユーザー 明智重蔵明智重蔵
提出日時 2015-07-20 16:42:50
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 1,943 bytes
コンパイル時間 3,555 ms
コンパイル使用メモリ 109,352 KB
実行使用メモリ 23,996 KB
最終ジャッジ日時 2023-09-08 16:21:13
合計ジャッジ時間 5,411 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
21,816 KB
testcase_01 AC 62 ms
19,784 KB
testcase_02 AC 63 ms
23,900 KB
testcase_03 AC 62 ms
21,860 KB
testcase_04 AC 64 ms
23,908 KB
testcase_05 AC 80 ms
21,844 KB
testcase_06 AC 63 ms
23,968 KB
testcase_07 AC 81 ms
21,808 KB
testcase_08 AC 62 ms
21,836 KB
testcase_09 AC 64 ms
21,888 KB
testcase_10 AC 82 ms
21,792 KB
testcase_11 AC 62 ms
23,984 KB
testcase_12 AC 60 ms
23,992 KB
testcase_13 AC 62 ms
21,916 KB
testcase_14 AC 60 ms
21,768 KB
testcase_15 AC 62 ms
19,744 KB
testcase_16 AC 61 ms
21,840 KB
testcase_17 AC 64 ms
23,996 KB
testcase_18 AC 69 ms
23,964 KB
testcase_19 AC 77 ms
19,772 KB
testcase_20 AC 78 ms
21,932 KB
testcase_21 AC 77 ms
23,952 KB
testcase_22 AC 76 ms
23,880 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;

class Program
{
    static string InputPattern = "Input4";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3");
            WillReturn.Add("1 2 3");
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5");
            WillReturn.Add("1 2 3 4 5");
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("15");
            WillReturn.Add("62 8 90 2 24 62 38 64 76 60 30 76 80 74 72");
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] OmoriArr =
            InputList.Skip(1).SelectMany(X => X.Split(' '), (X, Y) => int.Parse(Y)).ToArray();

        //事前に総和の半分を求めておく
        int OmoriSum = OmoriArr.Sum();

        //総和が奇数なら解なし
        if (OmoriSum % 2 == 1) {
            Console.WriteLine("impossible");
            return;
        }

        //作成可能な和を保持する配列
        bool[] CanCreateNum = new bool[OmoriSum / 2 + 1];
        CanCreateNum[0] = true;

        for (int I = 0; I <= OmoriArr.GetUpperBound(0); I++) {
            //同じ数を複数回使ってしますので、リバースループにする必要あり
            for (int J = CanCreateNum.GetUpperBound(0); 0 <= J; J--) {
                if (CanCreateNum[J] == false) continue;
                int wkInd = J + OmoriArr[I];
                if (wkInd <= CanCreateNum.GetUpperBound(0))
                    CanCreateNum[wkInd] = true;
            }
        }
        Console.WriteLine(CanCreateNum[OmoriSum / 2] ? "possible" : "impossible");
    }
}
0