結果

問題 No.90 品物の並び替え
ユーザー te-shte-sh
提出日時 2016-08-30 11:45:17
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,078 ms / 5,000 ms
コード長 793 bytes
コンパイル時間 919 ms
コンパイル使用メモリ 114,092 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 21:35:40
合計ジャッジ時間 2,890 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 76 ms
4,368 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 7 ms
4,372 KB
testcase_04 AC 10 ms
4,368 KB
testcase_05 AC 89 ms
4,368 KB
testcase_06 AC 62 ms
4,368 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 1,078 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range;
import std.string, std.conv, std.bigint, std.math, std.random;
import std.stdio, std.typecons;

alias Tuple!(int, "i1", int, "i2", int, "sc") row;

void main()
{
  auto rd = readln.split.map!(to!int);
  auto n = rd[0];
  auto m = rd[1];
  auto tbl = iota(m).map!((_) {
    auto rd = readln.split.map!(to!int);
    return row(rd[0], rd[1], rd[2]);
  }).array;

  auto max = 0;
  foreach (ai; iota(n).permutations) {
    auto r = calc(ai.array, tbl);
    if (r > max) max = r;
  }

  writeln(max);
}

int calc(int[] ai, row[] tbl)
{
  return tbl.map!((row) {
    auto f1 = ai.find(row.i1);
    auto f2 = ai.find(row.i2);
    if (!f1.empty && !f2.empty && f1.length > f2.length)
      return row.sc;
    else
      return 0;
  }).sum;
}
0