結果

問題 No.90 品物の並び替え
ユーザー 6soukiti296soukiti29
提出日時 2017-08-16 17:06:35
言語 Nim
(2.0.2)
結果
AC  
実行時間 248 ms / 5,000 ms
コード長 738 bytes
コンパイル時間 2,975 ms
コンパイル使用メモリ 68,552 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 14:42:28
合計ジャッジ時間 3,944 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 21 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 23 ms
4,380 KB
testcase_06 AC 17 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 248 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 36) Warning: imported and not used: 'math' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,algorithm,math

type
    item = tuple[a, b, score : int]
var
    N,M,a,b,c : int
    p : item
(N,M) = stdin.readline.split.map(parseInt)
var
    Items = newSeq[item](0)
    nodes = newSeq[int](N)
    ans : int
    
for n in 0..<N:
    nodes[n] = n
for m in 1..M:
    (a,b,c) = stdin.readline.split.map(parseInt)
    Items.add((a,b,c))
proc precedence[T](A : openarray[T]; a,b:T) : bool =
    for p in A:
        if p == a:
            return true
        elif p == b:
            return false
    return false


proc sum_score(): int =
    for t in Items:
        if nodes.precedence(t.a,t.b):
            result += t.score

ans = sum_score()
while nodes.nextPermutation:
    ans = max(sum_score(), ans)

echo ans
0