結果
問題 | No.572 妖精の演奏 |
ユーザー |
![]() |
提出日時 | 2017-10-14 01:00:53 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 861 ms / 2,000 ms |
コード長 | 3,128 bytes |
コンパイル時間 | 1,010 ms |
コンパイル使用メモリ | 114,196 KB |
実行使用メモリ | 26,972 KB |
最終ジャッジ日時 | 2024-11-17 11:58:59 |
合計ジャッジ時間 | 9,618 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();}}