結果

問題 No.517 壊れたアクセサリー
ユーザー むらためむらため
提出日時 2019-01-27 15:16:30
言語 Nim
(2.0.2)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 936 bytes
コンパイル時間 2,941 ms
コンパイル使用メモリ 70,864 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 03:05:13
合計ジャッジ時間 4,224 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import sequtils,algorithm,tables
template times*(n:int,body) = (for _ in 0..<n: body)

proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord

var V = initTable[char,char]()
proc scanCode(n:int) =
  n.times:
    var pre = getchar_unlocked()
    while true:
      let k = getchar_unlocked()
      if k < 'A' or k > 'Z' :
        if pre notin V : V[pre] = pre
        break
      if k notin V or V[pre] == pre : V[pre] = k
      pre = k

scan().scanCode()
scan().scanCode()
if toSeq(V.pairs).filterIt(it[0] == it[1]).len >= 2: quit "-1",0
proc interpret(start:char):string =
  result = ""
  var i = start
  while true:
    result &= i
    if i == V[i] : return
    i = V[i]
var answers = newSeq[string]()
for k in V.keys: answers &= interpret(k)
echo answers.sortedByIt(-it.len)[0]
0