結果

問題 No.572 妖精の演奏
ユーザー mbanmban
提出日時 2017-10-14 01:00:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 858 ms / 2,000 ms
コード長 3,128 bytes
コンパイル時間 1,420 ms
コンパイル使用メモリ 112,264 KB
実行使用メモリ 26,932 KB
最終ジャッジ日時 2024-04-28 17:49:45
合計ジャッジ時間 9,514 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
24,620 KB
testcase_01 AC 49 ms
26,932 KB
testcase_02 AC 50 ms
25,136 KB
testcase_03 AC 49 ms
26,796 KB
testcase_04 AC 37 ms
24,748 KB
testcase_05 AC 96 ms
24,872 KB
testcase_06 AC 137 ms
26,836 KB
testcase_07 AC 137 ms
24,792 KB
testcase_08 AC 132 ms
24,748 KB
testcase_09 AC 189 ms
24,692 KB
testcase_10 AC 841 ms
26,860 KB
testcase_11 AC 836 ms
26,712 KB
testcase_12 AC 846 ms
22,636 KB
testcase_13 AC 788 ms
24,672 KB
testcase_14 AC 858 ms
24,936 KB
testcase_15 AC 844 ms
26,844 KB
testcase_16 AC 850 ms
26,712 KB
testcase_17 AC 839 ms
24,796 KB
testcase_18 AC 78 ms
24,748 KB
testcase_19 AC 26 ms
22,836 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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
using System.Diagnostics;

class Scanner
{
    private readonly char Separator = ' ';
    private int Index = 0;
    private string[] Line = new string[0];
    public string Next()
    {
        if (Index >= Line.Length)
        {
            Line = Console.ReadLine().Split(Separator);
            Index = 0;
        }
        var ret = Line[Index];
        Index++;
        return ret;
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

}

class Magatro
{
    private int N, M;
    private int[,] A;
    private long[,,] Dp;

    private void Scan()
    {
        var s = new Scanner();
        N = s.NextInt();
        M = s.NextInt();
        A = new int[M, M];
        for (int i = 0; i < M; i++)
        {
            for (int j = 0; j < M; j++)
            {
                A[i, j] = s.NextInt();
            }
        }
    }

    public void Solve()
    {
        Scan();
        Dp = new long[M, M, 34];
        for (int n = 1; n <= 33; n++)
        {
            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < M; j++)
                {
                    for (int k = 0; k < M; k++)
                    {
                        for (int l = 0; l < M; l++)
                        {
                            if (n == 1)
                            {
                                if (i != k || l != j)
                                {
                                    continue;
                                }
                            }
                            Dp[i, j, n] = Math.Max(Dp[i, j, n], Dp[i, k, n - 1] + Dp[l, j, n - 1] + A[k, l]);
                        }
                    }
                }
            }
        }
        long[] ans = new long[M];
        bool flag = false;
        for (int i = 0; N > 0; i++, N /= 2)
        {
            if (N % 2 != 0)
            {
                if (!flag)
                {
                    for (int j = 0; j < M; j++)
                    {
                        for (int k = 0; k < M; k++)
                        {
                            ans[k] = Math.Max(ans[k], Dp[j, k, i]);
                        }
                    }
                    flag = true;
                }
                else
                {
                    var next = new long[M];
                    for (int j = 0; j < M; j++)
                    {
                        for (int k = 0; k < M; k++)
                        {
                            for (int l = 0; l < M; l++)
                            {
                                next[l] = Math.Max(next[l], ans[j] + Dp[k, l, i] + A[j, k]);
                            }
                        }
                    }
                    ans = next;
                }
            }
        }
        Console.WriteLine(ans.Max());
    }

    static public void Main()
    {
        new Magatro().Solve();

    }
}
0