結果

問題 No.519 アイドルユニット
ユーザー 明智重蔵明智重蔵
提出日時 2017-06-10 05:58:20
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,957 bytes
コンパイル時間 1,899 ms
コンパイル使用メモリ 112,172 KB
実行使用メモリ 289,332 KB
最終ジャッジ日時 2023-10-24 10:11:46
合計ジャッジ時間 6,693 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = "InputX";

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

        if (InputPattern == "Input1") {
            WillReturn.Add("4");
            WillReturn.Add("-1 16 15 38");
            WillReturn.Add("16 -1 22 17");
            WillReturn.Add("15 22 -1 19");
            WillReturn.Add("38 17 19 -1");
            //60
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("6");
            WillReturn.Add("-1 14 29 35 39 8");
            WillReturn.Add("14 -1 35 41 34 3");
            WillReturn.Add("29 35 -1 14 21 21");
            WillReturn.Add("35 41 14 -1 12 42");
            WillReturn.Add("39 34 21 12 -1 28");
            WillReturn.Add("8 3 21 42 28 -1");
            //116
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

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

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        int N = int.Parse(InputList[0]);

        var FArrList = new List<int[]>();

        foreach (string EachStr in InputList.Skip(1)) {
            SplitAct(EachStr);
            FArrList.Add(wkArr);
        }

        int UB = (1 << N) - 1;

        //相性度合計の最大値[登場した人のBit位置]なDP表
        var PrevDP = new Nullable<int>[UB + 1];
        PrevDP[0] = 0;

        //ペアの作成でループ
        for (int I = 1; I <= N / 2; I++) {
            var CurrDP = new Nullable<int>[UB + 1];
            for (int J = 0; J <= UB; J++) {
                if (PrevDP[J].HasValue == false) continue;

                for (int K = 0; K <= N - 1; K++) {
                    //使用済ならContinue
                    if ((J & DeriveBitPos(K)) > 0)
                        continue;

                    for (int L = K + 1; L <= N - 1; L++) {
                        //使用済ならContinue
                        if ((J & DeriveBitPos(L)) > 0)
                            continue;

                        int NewJ = J;
                        NewJ |= DeriveBitPos(K);
                        NewJ |= DeriveBitPos(L);

                        int NewVal = PrevDP[J].Value + FArrList[K][L];

                        if (CurrDP[NewJ].HasValue && NewVal <= CurrDP[NewJ])
                            continue;

                        CurrDP[NewJ] = NewVal;
                    }
                }
            }
            PrevDP = CurrDP;
        }
        Console.WriteLine(PrevDP[UB]);
    }

    //人番号を引数として対応するビット位置を返す
    static int DeriveBitPos(int pHitoNo)
    {
        return 1 << pHitoNo;
    }
}
0