結果

問題 No.572 妖精の演奏
ユーザー mbanmban
提出日時 2017-10-14 01:00:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 825 ms / 2,000 ms
コード長 3,128 bytes
コンパイル時間 2,258 ms
コンパイル使用メモリ 104,044 KB
実行使用メモリ 23,580 KB
最終ジャッジ日時 2023-08-11 00:40:58
合計ジャッジ時間 12,051 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
23,516 KB
testcase_01 AC 80 ms
23,492 KB
testcase_02 AC 80 ms
21,464 KB
testcase_03 AC 81 ms
21,508 KB
testcase_04 AC 70 ms
21,604 KB
testcase_05 AC 122 ms
23,580 KB
testcase_06 AC 157 ms
19,556 KB
testcase_07 AC 158 ms
21,572 KB
testcase_08 AC 163 ms
21,420 KB
testcase_09 AC 211 ms
23,448 KB
testcase_10 AC 818 ms
21,452 KB
testcase_11 AC 800 ms
19,524 KB
testcase_12 AC 804 ms
21,532 KB
testcase_13 AC 804 ms
21,564 KB
testcase_14 AC 793 ms
21,552 KB
testcase_15 AC 802 ms
21,420 KB
testcase_16 AC 805 ms
21,472 KB
testcase_17 AC 825 ms
23,576 KB
testcase_18 AC 110 ms
21,368 KB
testcase_19 AC 64 ms
21,464 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