結果

問題 No.762 PDCAパス
ユーザー むらため
提出日時 2019-01-17 12:31:56
言語 Nim
(2.2.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,080 bytes
コンパイル時間 2,836 ms
コンパイル使用メモリ 67,124 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-01 06:56:49
合計ジャッジ時間 4,252 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 54) Warning: imported and not used: 'strformat' [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, 47) Warning: imported and not used: 'macros' [UnusedImport]
/home/judge/data/code/Main.nim(1, 41) Warning: imported and not used: 'sugar' [UnusedImport]

ソースコード

diff #

import sequtils,strutils,algorithm,math,sugar,macros,strformat
template times*(n:int32,body) = (for _ in 0..<n: body)
template `max=`*(x,y) = x = max(x,y)
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int32 =
  var minus = false
  while true:
    var k = getchar_unlocked()
    if k == '-' : minus = true
    elif k < '0' or k > '9': break
    else: result = 10 * result + k.ord.int32 - '0'.ord.int32
  if minus: result *= -1

proc scanf(formatstr: cstring){.header: "<stdio.h>", varargs.}

let n = scan()
let m = scan()
var S: array[10_0010,char]
for i in 0..<n:S[i] = getchar_unlocked()
discard getchar_unlocked()
var D = newSeq[int32]()
var C = newSeq[int32]()
var A = newSeq[int32]()
var ans = newSeq[int32](n)
m.times:
  var u = scan() - 1
  var v = scan() - 1
  if S[u] < S[v]: u.swap(v)
  if S[u] == 'P' and S[v] == 'D'   : ans[v] += 1
  elif S[u] == 'D' and S[v] == 'C' :
    D &= u
    C &= v
  elif S[u] == 'C' and S[v] == 'A' : A &= u
for i in 0..<D.len: ans[C[i]] += ans[D[i]]
echo A.mapIt(ans[it]).sum() mod 1000000007
0