結果
問題 | No.826 連絡網 |
ユーザー | むらため |
提出日時 | 2019-05-20 04:56:02 |
言語 | Nim (2.0.2) |
結果 |
AC
|
実行時間 | 362 ms / 2,000 ms |
コード長 | 1,528 bytes |
コンパイル時間 | 2,467 ms |
コンパイル使用メモリ | 67,084 KB |
実行使用メモリ | 10,928 KB |
最終ジャッジ日時 | 2023-09-14 18:35:35 |
合計ジャッジ時間 | 6,191 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 3 ms
4,376 KB |
testcase_04 | AC | 3 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 3 ms
4,376 KB |
testcase_08 | AC | 3 ms
4,376 KB |
testcase_09 | AC | 3 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,376 KB |
testcase_11 | AC | 3 ms
4,380 KB |
testcase_12 | AC | 206 ms
8,812 KB |
testcase_13 | AC | 70 ms
5,216 KB |
testcase_14 | AC | 138 ms
7,204 KB |
testcase_15 | AC | 13 ms
4,376 KB |
testcase_16 | AC | 89 ms
5,776 KB |
testcase_17 | AC | 70 ms
5,244 KB |
testcase_18 | AC | 53 ms
4,892 KB |
testcase_19 | AC | 250 ms
9,540 KB |
testcase_20 | AC | 251 ms
9,340 KB |
testcase_21 | AC | 4 ms
4,376 KB |
testcase_22 | AC | 71 ms
5,440 KB |
testcase_23 | AC | 92 ms
5,836 KB |
testcase_24 | AC | 37 ms
4,380 KB |
testcase_25 | AC | 334 ms
10,928 KB |
testcase_26 | AC | 46 ms
4,632 KB |
testcase_27 | AC | 218 ms
8,824 KB |
testcase_28 | AC | 150 ms
7,512 KB |
testcase_29 | AC | 66 ms
5,124 KB |
testcase_30 | AC | 362 ms
10,924 KB |
testcase_31 | AC | 84 ms
5,668 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: 'math' [UnusedImport]
ソースコード
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 p in self.parent:(if p == self.parent[x]: result += 1) useUnionFind() let n = scan() let p = scan() var F = newUnionFind[int](n+1) for i in 2..n: for j in countup(i,n,i): F.merge(i,j) # echo F.parent # echo F.parent[p] echo F.count(p)