結果

問題 No.90 品物の並び替え
ユーザー kaiyori_labkaiyori_lab
提出日時 2014-12-07 20:11:57
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 68 ms / 5,000 ms
コード長 787 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 92,500 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 19:20:03
合計ジャッジ時間 1,374 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

void main(){

  auto buf = readln.chomp.split(" ").map!(to!int);
  int N = buf[0];
  int M = buf[1];
  int[][] pointTable = new int[][](N+1, N+1);

  int getPoint(int[] arr, int acc = 0){
    if(!arr.length) return acc;
    int tempPoint;
    foreach(e; arr[1..$]){ tempPoint += pointTable[arr[0]][e]; }
    return getPoint(arr[1..$], acc + tempPoint);
  }
  
  foreach(i; 0..M){
    auto buf2 = readln.chomp.split(" ").map!(to!int);
    pointTable[buf2[0]][buf2[1]] = buf2[2];
  }

  int res = 0;
  int[] items = iota(0, N).array;
  do{
    if(getPoint(items) > res) res = getPoint(items);
  } while(nextPermutation(items));
  res.writeln;
}
0