結果

問題 No.539 インクリメント
ユーザー むらためむらため
提出日時 2019-01-26 13:43:43
言語 Nim
(2.0.2)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,619 bytes
コンパイル時間 3,124 ms
コンパイル使用メモリ 66,476 KB
実行使用メモリ 7,532 KB
最終ジャッジ日時 2023-09-14 02:56:27
合計ジャッジ時間 3,566 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 78 ms
5,420 KB
testcase_02 AC 40 ms
7,532 KB
testcase_03 AC 41 ms
7,504 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]
/home/judge/data/code/Main.nim(1, 27) Warning: imported and not used: 'strutils' [UnusedImport]

ソースコード

diff #

import sequtils,algorithm,strutils
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

proc printf(formatstr: cstring){.header: "<stdio.h>", varargs.}
proc putchar_unlocked(c:char){. importc:"putchar_unlocked",header: "<stdio.h>" .}


proc parse(lastNumIndex:var int): seq[tuple[str:string,isNum:bool]] =
  result = @[]
  var length = 0
  var current = ""
  var isNum = false
  while true:
    let k = getchar_unlocked()
    if k.ord < 32 or k.ord > 126 :
      result &= (current,isNum)
      if isNum : lastNumIndex = length
      return
    let kIsNum = k >= '0' and k <= '9'
    if isNum xor kIsNum and current != "":
      result &= (current,isNum)
      if isNum : lastNumIndex = length
      length += 1
      current = ""
    current &= k
    isNum = kIsNum

proc add1(S:string):string =
  result = ""
  var ch = 1
  for i in (S.len-1).countdown(0):
    let c = S[i].ord - '0'.ord
    let d = c + ch
    if d < 10 :
      result &= ('0'.ord + d).chr
      ch = 0
    else:
      result &= ('0'.ord + d mod 10).chr
      ch = 1
  if ch > 0: result &= ('0'.ord + ch).chr
  result.reverse()

scan().times:
  var lastNumIndex = -1
  let P = parse(lastNumIndex)
  for i in 0..<P.len:
    if i != lastNumIndex:
      for j in 0..<P[i].str.len:
        putchar_unlocked(P[i].str[j])
    else:
      let S = P[i].str.add1()
      for j in 0..<S.len:
        putchar_unlocked(S[j])
  putchar_unlocked('\n')
0