Submission #1863358


Source Code Expand

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const ll mod = 1e9+7;

vector<int> G[214514];

ll mpow(ll a, ll b){
	if(b == 0) return 1;
	if(b < 0) return 0;
	if(b%2) return (a*mpow(a, b-1))%mod;
	ll ret = mpow(a, b/2);
	return (ret*ret)%mod;
}

ll dp[2010][2] = {};
ll cd[214514] = {};

void init(int v, int dd){
	cd[dd]++;
	REP(i, G[v].size()){
		init(G[v][i], dd+1);
	}
}

void dfs(int v, int d){
	if(d == 0){
		dp[v][0] = dp[v][1] = 1;
		return;
	}
	ll mul = 1, mul2 = 1;;
	REP(i, G[v].size()){
		dfs(G[v][i], d-1);
		mul *= dp[G[v][i]][0];
		mul %= mod;
		mul2 = (mul2 * (dp[G[v][i]][0]+dp[G[v][i]][1]))%mod;
	}
	REP(i, G[v].size()){
		dp[v][1] += ((mul*mpow(dp[G[v][i]][0], mod-2))%mod*dp[G[v][i]][1])%mod;
		dp[v][1] %= mod;
	}
	dp[v][0] = (mul2-dp[v][1]+mod)%mod;
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	if(N > 2000) return 0;
	REP(i, N){
		int p;
		cin >> p;
		G[p].push_back(i+1);
	}
	init(0, 0);
	ll res= 0;
	REP(i, N+1){
		REP(j, 2010) REP(k, 2)
			dp[j][k] = 0;
		dfs(0, i);
		res = (res+dp[0][1]*mpow(2, N-cd[i]+1))%mod;
	}
	cout << res << endl;
}

Submission Info

Submission Time
Task E - Smuggling Marbles
User maze1230
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1832 Byte
Status WA
Exec Time 1161 ms
Memory 5504 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 400 / 400 0 / 600
Status
AC × 3
AC × 20
AC × 20
WA × 32
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
Subtask1 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s1_09.txt, s1_10.txt, s1_11.txt, s1_12.txt, s1_13.txt, s1_14.txt, s1_15.txt, s1_16.txt, s1_17.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s1_09.txt, s1_10.txt, s1_11.txt, s1_12.txt, s1_13.txt, s1_14.txt, s1_15.txt, s1_16.txt, s1_17.txt, s2_01.txt, s2_02.txt, s2_03.txt, s2_04.txt, s2_05.txt, s2_06.txt, s2_07.txt, s2_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt, s2_15.txt, s2_16.txt, s2_17.txt, s2_18.txt, s2_19.txt, s2_20.txt, s2_21.txt, s2_22.txt, s2_23.txt, s2_24.txt, s2_25.txt, s2_26.txt, s2_27.txt, s2_28.txt, s2_29.txt, s2_30.txt, s2_31.txt, s2_32.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 3 ms 5376 KB
00_example_02.txt AC 3 ms 5376 KB
00_example_03.txt AC 3 ms 5376 KB
s1_01.txt AC 139 ms 5376 KB
s1_02.txt AC 87 ms 5376 KB
s1_03.txt AC 432 ms 5376 KB
s1_04.txt AC 4 ms 5376 KB
s1_05.txt AC 64 ms 5376 KB
s1_06.txt AC 1127 ms 5376 KB
s1_07.txt AC 86 ms 5376 KB
s1_08.txt AC 578 ms 5504 KB
s1_09.txt AC 46 ms 5376 KB
s1_10.txt AC 1142 ms 5376 KB
s1_11.txt AC 87 ms 5376 KB
s1_12.txt AC 429 ms 5376 KB
s1_13.txt AC 4 ms 5376 KB
s1_14.txt AC 1161 ms 5376 KB
s1_15.txt AC 1161 ms 5376 KB
s1_16.txt AC 1151 ms 5376 KB
s1_17.txt AC 1161 ms 5376 KB
s2_01.txt WA 3 ms 5248 KB
s2_02.txt WA 3 ms 5248 KB
s2_03.txt WA 3 ms 5248 KB
s2_04.txt WA 3 ms 5248 KB
s2_05.txt WA 3 ms 5248 KB
s2_06.txt WA 3 ms 5248 KB
s2_07.txt WA 3 ms 5248 KB
s2_08.txt WA 3 ms 5248 KB
s2_09.txt WA 3 ms 5248 KB
s2_10.txt WA 3 ms 5248 KB
s2_11.txt WA 3 ms 5248 KB
s2_12.txt WA 3 ms 5248 KB
s2_13.txt WA 3 ms 5248 KB
s2_14.txt WA 3 ms 5248 KB
s2_15.txt WA 3 ms 5248 KB
s2_16.txt WA 3 ms 5248 KB
s2_17.txt WA 3 ms 5248 KB
s2_18.txt WA 3 ms 5248 KB
s2_19.txt WA 3 ms 5248 KB
s2_20.txt WA 3 ms 5248 KB
s2_21.txt WA 3 ms 5248 KB
s2_22.txt WA 3 ms 5248 KB
s2_23.txt WA 3 ms 5248 KB
s2_24.txt WA 3 ms 5248 KB
s2_25.txt WA 3 ms 5248 KB
s2_26.txt WA 3 ms 5248 KB
s2_27.txt WA 3 ms 5248 KB
s2_28.txt WA 3 ms 5248 KB
s2_29.txt WA 3 ms 5248 KB
s2_30.txt WA 3 ms 5248 KB
s2_31.txt WA 3 ms 5248 KB
s2_32.txt WA 3 ms 5248 KB