結果
問題 | No.778 クリスマスツリー |
ユーザー | flippergo |
提出日時 | 2021-02-28 13:57:38 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 552 bytes |
コンパイル時間 | 152 ms |
コンパイル使用メモリ | 82,372 KB |
実行使用メモリ | 140,904 KB |
最終ジャッジ日時 | 2024-04-10 15:58:30 |
合計ジャッジ時間 | 4,023 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
54,460 KB |
testcase_01 | AC | 32 ms
53,400 KB |
testcase_02 | AC | 31 ms
52,600 KB |
testcase_03 | AC | 31 ms
52,888 KB |
testcase_04 | AC | 31 ms
52,816 KB |
testcase_05 | AC | 31 ms
53,508 KB |
testcase_06 | RE | - |
testcase_07 | AC | 176 ms
140,904 KB |
testcase_08 | RE | - |
testcase_09 | AC | 390 ms
118,176 KB |
testcase_10 | AC | 396 ms
118,240 KB |
testcase_11 | AC | 392 ms
118,308 KB |
testcase_12 | AC | 436 ms
121,212 KB |
testcase_13 | AC | 202 ms
121,004 KB |
testcase_14 | RE | - |
ソースコード
N = int(input()) A = list(map(int,input().split())) A.insert(0,0) G = {i:[] for i in range(1,N+1)} for i in range(1,N): a = A[i]+1 G[a].append(i+1) k = 0 while 2**k<N: k += 1 K = 2**k B = [0 for _ in range(K+1)] def update(i,x): j = i while j<=K: B[j] += x j += j&(-j) def csum(i): j = i tot = 0 while j>0: tot += B[j] j -= j&(-j) return tot cnt = 0 def dfs(i): global cnt cnt += csum(i) update(i,1) for j in G[i]: dfs(j) update(j,-1) dfs(1) print(cnt)