結果

問題 No.572 妖精の演奏
ユーザー ikdikd
提出日時 2017-10-07 15:10:31
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 959 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 87,724 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 16:19:25
合計ジャッジ時間 1,986 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  
  long n; int m;
  rd(n); rd(m);
  auto c=new long[][](m, m);
  foreach(i; 0..m) c[i]=readln.split.to!(long[]);

  auto d=new long[][][](33, m, m);
  foreach(k; 0..33)foreach(i; 0..m)foreach(j; 0..m){
    if(k==0){
      d[k][i][j]=c[i][j];
    }else{
      foreach(_; 0..m) chmax(d[k][i][j], d[k-1][i][_]+d[k-1][_][j]);
    }
  }

  long mx=0;
  foreach(s; 0..m){
    auto dp=new long[][](33, m);
    if((n-1)&1)foreach(j; 0..m) dp[0][j]=d[0][s][j];
    foreach(k; 1..33)foreach(j; 0..m){
      if((n-1)&(1L<<k)){
        foreach(i; 0..m) chmax(dp[k][j], dp[k-1][i]+d[k][i][j]);
      }else{
        dp[k][j]=dp[k-1][j];
      }
    }
    chmax(mx, dp[32].maxElement);
  }

  writeln(mx);
}

void chmax(T)(ref T x, T y){
  if(x<y) x=y;
}


void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
0