結果

問題 No.628 Tagの勢い
ユーザー varrhovarrho
提出日時 2019-09-24 00:22:18
言語 Nim
(2.0.2)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 746 bytes
コンパイル時間 4,452 ms
コンパイル使用メモリ 66,376 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 08:34:51
合計ジャッジ時間 5,378 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import algorithm, sequtils, strutils
type No0628 = tuple[tag: string, val: int]
proc mycmp(x, y: No0628): int =
  if x.val != y.val:
    if x.val < y.val: 1 else: -1
  else:
    if x.tag < y.tag: -1 else: 1
let
  n: int = stdin.readline.parseInt
  a: seq[string] = mapIt(0..<(3 * n), stdin.readline)
var
  tags: seq[string]
  vals: seq[int]
  ans: seq[No0628]
for i in 0..<n:
  var
    s: seq[int] = a[3 * i + 1].split.map(parseInt)
    t: seq[string] = a[3 * i + 2].split
  for j in 0..<s[0]:
    if tags.find(t[j]) == -1:
      tags.add(t[j])
      vals.add(s[1])
    else:
      vals[tags.find(t[j])] += s[1]
for i in 0..<tags.len:
  ans.add((tags[i], vals[i]))
ans.sort(mycmp)
for i in 0..<min(10, ans.len):
  echo ans[i].tag, ' ', ans[i].val
0