結果
問題 | No.778 クリスマスツリー |
ユーザー | t33f |
提出日時 | 2018-12-25 22:13:34 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 151 ms / 2,000 ms |
コード長 | 599 bytes |
コンパイル時間 | 738 ms |
コンパイル使用メモリ | 75,160 KB |
実行使用メモリ | 27,776 KB |
最終ジャッジ日時 | 2024-04-22 03:03:48 |
合計ジャッジ時間 | 2,536 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
8,188 KB |
testcase_01 | AC | 5 ms
8,136 KB |
testcase_02 | AC | 4 ms
8,276 KB |
testcase_03 | AC | 5 ms
8,192 KB |
testcase_04 | AC | 5 ms
8,184 KB |
testcase_05 | AC | 5 ms
8,336 KB |
testcase_06 | AC | 97 ms
27,720 KB |
testcase_07 | AC | 44 ms
9,640 KB |
testcase_08 | AC | 151 ms
18,424 KB |
testcase_09 | AC | 136 ms
12,180 KB |
testcase_10 | AC | 123 ms
12,232 KB |
testcase_11 | AC | 138 ms
12,160 KB |
testcase_12 | AC | 127 ms
12,224 KB |
testcase_13 | AC | 83 ms
12,052 KB |
testcase_14 | AC | 98 ms
27,776 KB |
ソースコード
#include <set> #include <vector> #include <algorithm> #include <iostream> using namespace std; int n; vector<int> children[200100]; int bit[200100]; long long dfs(int i) { long long sum = 0; for (int x = i+1; x <= n+1; x += x&-x) bit[x]++; for (int j : children[i]) { for (int x = j+1; x > 0; x -= x&-x) sum += bit[x]; sum += dfs(j); } for (int x = i+1; x <= n+1; x += x&-x) bit[x]--; return sum; } int main () { cin >> n; for (int i = 1; i < n; i++) { int p; cin >> p; children[p].push_back(i); } cout << dfs(0) << endl; }