結果

問題 No.778 クリスマスツリー
ユーザー むらためむらため
提出日時 2019-01-30 00:32:23
言語 Nim
(2.0.2)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 2,862 ms
コンパイル使用メモリ 77,136 KB
実行使用メモリ 35,032 KB
最終ジャッジ日時 2024-04-22 03:07:03
合計ジャッジ時間 4,235 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 54 ms
35,032 KB
testcase_07 AC 22 ms
6,944 KB
testcase_08 AC 91 ms
20,992 KB
testcase_09 AC 82 ms
8,832 KB
testcase_10 AC 78 ms
9,088 KB
testcase_11 AC 79 ms
8,832 KB
testcase_12 AC 73 ms
8,920 KB
testcase_13 AC 30 ms
6,944 KB
testcase_14 AC 55 ms
34,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(4, 1) Warning: template 'stopwatch' is implicitly redefined; this is deprecated, add an explicit .redefine pragma [ImplicitTemplateRedefinition]
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #

import sequtils
import times
template stopwatch(body) = (let t1 = cpuTime();body;echo "TIME:",(cpuTime() - t1) * 1000,"ms")
template stopwatch(body) = body
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': return
    result = 10 * result + k.ord - '0'.ord

let n = scan()
var data: array[200010,int32]
var E : array[200010,seq[int32]]
proc update(i:int,val:int32) =
  var i = i
  while i < n:
    data[i] += val
    i = i or (i + 1)
proc get*(i:int): int32 =
  var i = i
  while i >= 0:
    result += data[i]
    i = (i and (i + 1)) - 1

stopwatch:
  for i in 1.int32..<n.int32: E[scan()] &= i
  proc solve(x:int): int =
    result += get(x)
    update(x, 1)
    for e in E[x]: result += solve(e)
    update(x, -1)
  stopwatch:
    echo solve(0)
0