結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 86 ms
52,620 KB
testcase_07 AC 28 ms
9,116 KB
testcase_08 AC 1,362 ms
30,348 KB
testcase_09 AC 84 ms
11,120 KB
testcase_10 AC 77 ms
11,260 KB
testcase_11 AC 77 ms
11,360 KB
testcase_12 AC 59 ms
11,356 KB
testcase_13 AC 40 ms
11,296 KB
testcase_14 AC 82 ms
52,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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