結果

問題 No.826 連絡網
ユーザー むらためむらため
提出日時 2019-05-20 04:52:39
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 1,536 bytes
コンパイル時間 3,521 ms
コンパイル使用メモリ 66,560 KB
実行使用メモリ 10,812 KB
最終ジャッジ日時 2023-09-14 18:34:13
合計ジャッジ時間 5,513 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #

import sequtils,math
template times*(n:int,body) = (for _ in 0..<n: body)
template `max=`*(x,y) = x = max(x,y)
template `min=`*(x,y) = x = min(x,y)
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" ,discardable.}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': return
    result = 10 * result + k.ord - '0'.ord
template useUnionFind() = # 同一集合の判定/マージ が 実質 O(1)
  type UnionFind[T] = ref object
    parent : seq[T]
  proc newUnionFind[T](size:int) : UnionFind[T] =
    new(result)
    result.parent = newSeqUninitialized[T](size)
    for i in 0.int32..<size.int32: result.parent[i] = i
  proc root[T](self:var UnionFind[T],x:T): T =
    if self.parent[x] == x: return x
    self.parent[x] = self.root(self.parent[x])
    return self.parent[x]
  proc same[T](self:var UnionFind[T],x,y:T) : bool = self.root(x) == self.root(y)
  proc merge[T](self:var UnionFind[T],sx,sy:T) : bool {.discardable.} =
    var rx = self.root(sx)
    var ry = self.root(sy)
    if rx == ry : return false
    if self.parent[ry] < self.parent[rx] : swap(rx,ry)
    if self.parent[rx] == self.parent[ry] : self.parent[rx] -= 1
    self.parent[ry] = rx
    return true
  proc count[T](self:var UnionFind[T],x:T):int =
    for i in 0..<self.parent.len:
      if self.parent[i] == self.parent[x]: result += 1
useUnionFind()

let n = scan()
let p = scan()
var F = newUnionFind[int](n+1)
for i in 2..n.float.sqrt.int+1:
  for j in countup(i,n,i):
    F.merge(i,j)
echo F.count(p)
0