結果

問題 No.778 クリスマスツリー
ユーザー cielciel
提出日時 2019-01-03 03:12:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,364 ms / 2,000 ms
コード長 498 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 77,956 KB
実行使用メモリ 52,620 KB
最終ジャッジ日時 2024-04-22 03:05:05
合計ジャッジ時間 3,475 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 85 ms
52,552 KB
testcase_07 AC 27 ms
9,248 KB
testcase_08 AC 1,364 ms
30,268 KB
testcase_09 AC 78 ms
11,352 KB
testcase_10 AC 82 ms
11,260 KB
testcase_11 AC 83 ms
11,208 KB
testcase_12 AC 65 ms
11,244 KB
testcase_13 AC 42 ms
11,308 KB
testcase_14 AC 85 ms
52,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
using namespace std;

vector<vector<int> >v;
deque<int> a;
long long dfs(int cur){
	auto it=lower_bound(a.begin(),a.end(),cur);
	int k=distance(a.begin(),it);
	long long r=k;
	a.insert(it,cur);
	for(auto &e:v[cur])r+=dfs(e);
	a.erase(a.begin()+k);
	return r;
}

int main(){
	int N,x;
	scanf("%d",&N);
	v.resize(N);
	for(int i=1;i<N;i++)scanf("%d",&x),v[x].push_back(i);
	printf("%lld\n",dfs(0));
}
0