結果

問題 No.539 インクリメント
ユーザー むらためむらため
提出日時 2019-01-26 14:15:16
言語 Nim
(2.0.2)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,875 bytes
コンパイル時間 2,506 ms
コンパイル使用メモリ 66,236 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 02:56:45
合計ジャッジ時間 3,418 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 16 ms
4,380 KB
testcase_02 AC 17 ms
4,376 KB
testcase_03 AC 18 ms
4,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]
/home/judge/data/code/Main.nim(1, 17) Warning: imported and not used: 'algorithm' [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>" .}


var preAlphabets : array[1_00010,char]
var preNums : array[1_00010,char]
template printNums(n:int) =
  for i in 0..<n: putchar_unlocked(preNums[i])
template printAlphabets(n:int) =
  for i in 0..<n: putchar_unlocked(preAlphabets[i])

proc printAdd1(length:int) =
  var ch = 1
  for i in (length-1).countdown(0):
    let c = preNums[i].ord - '0'.ord
    let d = c + ch
    if d < 10 :
      preNums[i] = ('0'.ord + d).chr
      ch = 0
    else:
      preNums[i] = ('0'.ord + d mod 10).chr
      ch = 1
  if ch > 0: putchar_unlocked(('0'.ord + ch).chr)
  for i in 0..<length: putchar_unlocked(preNums[i])

proc impl()  =
  var preAlphabetsLen = 0
  var preNumsLen = 0
  var isNum = false
  while true:
    let k = getchar_unlocked()
    if k.ord < 32 or k.ord > 126 :
      if isNum:
        if preAlphabetsLen > 0 : printAlphabets(preAlphabetsLen)
        printAdd1(preNumsLen)
      else:
        if preNumsLen > 0:
          printAdd1(preNumsLen)
        printAlphabets(preAlphabetsLen)
      putchar_unlocked('\n')
      return
    let kIsNum = k >= '0' and k <= '9'
    if kIsNum and not isNum:
      if preNums.len > 0:
        printNums(preNumsLen)
        preNumsLen = 0
      printAlphabets(preAlphabetsLen)
      preAlphabetsLen = 0
    if kIsNum:
      preNums[preNumsLen] = k
      preNumsLen += 1
    else:
      preAlphabets[preAlphabetsLen] = k
      preAlphabetsLen += 1
    isNum = kIsNum


scan().times: impl()
0