結果

問題 No.90 品物の並び替え
ユーザー toshiro_yanagitoshiro_yanagi
提出日時 2019-01-06 07:07:38
言語 Nim
(2.0.2)
結果
AC  
実行時間 428 ms / 5,000 ms
コード長 889 bytes
コンパイル時間 2,943 ms
コンパイル使用メモリ 68,176 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 22:08:04
合計ジャッジ時間 4,047 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import strutils


proc nextString: string =
  result = ""
  while not endOfFile stdin:
    let nextChar = readChar stdin
    case nextChar
    of '\r':
      discard
    of "\n"[0], ' ':
      break
    else:
      add result, nextChar


proc nextInt: int =
  parseInt nextString()


let
  n, m = nextInt()

var
  scoreList = newSeq[tuple[item1, item2, score: int]](m)
  ans = 0


proc calcScore(items: seq[int], x: int): int =
  for i in 0 ..< m:
    if x == scoreList[i].item2 and scoreList[i].item1 in items:
      result += scoreList[i].score


proc dfs(items: seq[int], score: int) =
  if items.len == n:
    ans = max(ans, score)
    return

  for i in 0 ..< n:
    if i notin items:
      dfs(items & i, score + calcScore(items, i))


proc main: void =
  for i in 0 ..< m:
    scoreList[i] = (nextInt(), nextInt(), nextInt())

  dfs(@[], 0)
  echo ans


when isMainModule:
  main()
0