結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 80 ms
52,408 KB
testcase_07 AC 25 ms
8,984 KB
testcase_08 AC 1,275 ms
30,352 KB
testcase_09 AC 66 ms
11,252 KB
testcase_10 AC 65 ms
11,220 KB
testcase_11 AC 76 ms
11,280 KB
testcase_12 AC 52 ms
11,400 KB
testcase_13 AC 41 ms
11,244 KB
testcase_14 AC 81 ms
52,544 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