結果

問題 No.592 括弧の対応 (2)
ユーザー むらためむらため
提出日時 2019-01-18 12:02:52
言語 Nim
(2.0.2)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,018 bytes
コンパイル時間 2,763 ms
コンパイル使用メモリ 66,360 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 02:11:18
合計ジャッジ時間 3,248 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 15 ms
4,376 KB
testcase_02 AC 13 ms
4,380 KB
testcase_03 AC 13 ms
4,376 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: 'strutils' [UnusedImport]
/home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'algorithm' [UnusedImport]
/home/judge/data/code/Main.nim(1, 36) Warning: imported and not used: 'math' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,algorithm,math

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

proc putchar_unlocked(c:char){.header: "<stdio.h>" .}
proc printInt(a:int32) =
  if a == 0:
    putchar_unlocked('0')
    return
  var n = a
  var rev = a
  var cnt = 0
  while rev mod 10 == 0:
    cnt += 1
    rev = rev div 10
  rev = 0
  while n != 0:
    rev = (rev shl 3) + (rev shl 1) + n mod 10
    n = n div 10
  while rev != 0:
    putchar_unlocked((rev mod 10 + '0'.ord).chr)
    rev = rev div 10
  while cnt != 0:
    putchar_unlocked('0')
    cnt -= 1



let n = scan()
var A : array[200010,int32]
var s : array[100010,int32]
var si = 0

for i in 1.int32 .. n.int32:
  if getchar_unlocked() == '(':
    s[si] = i
    si += 1
  else:
    A[i] = s[si-1]
    A[A[i]] = i
    si -= 1
for i in 1..n:
  A[i].printInt()
  putchar_unlocked('\n')
0