結果

問題 No.90 品物の並び替え
ユーザー te-shte-sh
提出日時 2017-01-27 11:59:05
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 131 ms / 5,000 ms
コード長 513 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 97,056 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-03 00:55:13
合計ジャッジ時間 1,786 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 14 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 14 ms
4,376 KB
testcase_06 AC 14 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,500 KB
testcase_09 AC 131 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd1 = readln.split.to!(size_t[]), n = rd1[0], m = rd1[1];

  auto score = new int[][](n, n);
  foreach (_; m.iota) {
    auto rd2 = readln.split.to!(int[]);
    score[rd2[0]][rd2[1]] = rd2[2];
  }

  auto calcScore(Range)(Range ai) {
    auto r = 0;
    foreach (i, a; ai.enumerate)
      foreach (b; ai[i+1..$])
        r += score[a][b];
    return r;
  }

  writeln(n.iota.permutations.map!(a => calcScore(a)).fold!max);
}
0