Submission #1077444

# Submission time Handle Problem Language Result Execution time Memory
1077444 2024-08-27T07:17:12 Z Faisal_Saqib Digital Circuit (IOI22_circuit) C++17
22 / 100
3000 ms 12112 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll NP=2e5+100,mod=1e9+2022;
ll n,m,p[NP],a[NP];
vector<ll> ma[NP];
ll dp[NP][2];
void compute(int x,bool recur=1)
{
	dp[x][0]=dp[x][1]=0;
	if(n<=x){
		dp[x][a[x-n]]=1;
		return;
	}
	int sz=ma[x].size();
	vector<int> tmp(sz+1);
	tmp[0]=1;
	for(auto y:ma[x])
	{
		if(recur)
			compute(y);
		for(int j=sz;j>=0;j--)
		{
			if(j==0)
			{
				tmp[j]=(tmp[j]*dp[y][0])%mod;
			}
			else
			{
				tmp[j]=(tmp[j]*dp[y][0])%mod;
				tmp[j]=(tmp[j] + ((tmp[j-1]*dp[y][1])%mod))%mod;
			}
		}
	}
	int sm=0;
	for(int j=sz;j>=1;j--)
	{
		sm = ( sm + tmp[j] ) % mod;
		dp[x][1] = ( dp[x][1] + sm ) % mod;
	}
	sm=tmp[0];
	for(int j=1;j<=sz;j++)
	{
		dp[x][0] = ( dp[x][0] + sm ) % mod;
		sm = ( sm + tmp[j] ) % mod;
	}
}
bool subtask=1;
void init(int N, int M, std::vector<int> P, std::vector<int> A)
{
	n=N,m=M;
	for(ll i=0;i<n+m;i++)
	{
		p[i]=P[i];
		if(p[i]!=-1)ma[p[i]].push_back(i),subtask&=((p[i]==((i-1)/2)));
	}
	for(ll j=0;j<m;j++)a[j]=A[j];
	compute(0);
}

int count_ways(int L, int R)
{
	for(ll i=L-n;i<=R-n;i++)a[i]=(a[i]?0:1);
	if(L==R)
	{
		int x=L;
		while(x>=0)
		{
			compute(x,0);
			x=p[x];
		}
	}
	else
	{
		compute(0);
	}
	return (int)dp[0][1];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 23 ms 5208 KB Output is correct
4 Correct 25 ms 5208 KB Output is correct
5 Correct 25 ms 5208 KB Output is correct
6 Correct 25 ms 5208 KB Output is correct
7 Correct 25 ms 5208 KB Output is correct
8 Correct 26 ms 4960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 2 ms 4952 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 2 ms 5208 KB Output is correct
10 Correct 4 ms 5208 KB Output is correct
11 Correct 3 ms 5208 KB Output is correct
12 Correct 4 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 23 ms 5208 KB Output is correct
4 Correct 25 ms 5208 KB Output is correct
5 Correct 25 ms 5208 KB Output is correct
6 Correct 25 ms 5208 KB Output is correct
7 Correct 25 ms 5208 KB Output is correct
8 Correct 26 ms 4960 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 2 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 2 ms 5208 KB Output is correct
17 Correct 2 ms 5208 KB Output is correct
18 Correct 4 ms 5208 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 4 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 3 ms 5208 KB Output is correct
23 Correct 3 ms 5208 KB Output is correct
24 Correct 3 ms 5148 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5208 KB Output is correct
29 Correct 27 ms 5208 KB Output is correct
30 Correct 24 ms 5208 KB Output is correct
31 Correct 2 ms 5208 KB Output is correct
32 Correct 3 ms 5208 KB Output is correct
33 Correct 3 ms 5208 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 7 ms 4952 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 25 ms 5208 KB Output is correct
38 Correct 25 ms 5208 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 3 ms 5208 KB Output is correct
41 Correct 3 ms 5208 KB Output is correct
42 Correct 3 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 527 ms 8536 KB Output is correct
2 Correct 793 ms 12112 KB Output is correct
3 Correct 812 ms 12112 KB Output is correct
4 Correct 841 ms 12112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 527 ms 8536 KB Output is correct
2 Correct 793 ms 12112 KB Output is correct
3 Correct 812 ms 12112 KB Output is correct
4 Correct 841 ms 12112 KB Output is correct
5 Execution timed out 3100 ms 8528 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 2 ms 4952 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 2 ms 5208 KB Output is correct
10 Correct 4 ms 5208 KB Output is correct
11 Correct 3 ms 5208 KB Output is correct
12 Correct 4 ms 5208 KB Output is correct
13 Correct 527 ms 8536 KB Output is correct
14 Correct 793 ms 12112 KB Output is correct
15 Correct 812 ms 12112 KB Output is correct
16 Correct 841 ms 12112 KB Output is correct
17 Execution timed out 3100 ms 8528 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 23 ms 5208 KB Output is correct
4 Correct 25 ms 5208 KB Output is correct
5 Correct 25 ms 5208 KB Output is correct
6 Correct 25 ms 5208 KB Output is correct
7 Correct 25 ms 5208 KB Output is correct
8 Correct 26 ms 4960 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 2 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 2 ms 5208 KB Output is correct
17 Correct 2 ms 5208 KB Output is correct
18 Correct 4 ms 5208 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 4 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 3 ms 5208 KB Output is correct
23 Correct 3 ms 5208 KB Output is correct
24 Correct 3 ms 5148 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5208 KB Output is correct
29 Correct 27 ms 5208 KB Output is correct
30 Correct 24 ms 5208 KB Output is correct
31 Correct 2 ms 5208 KB Output is correct
32 Correct 3 ms 5208 KB Output is correct
33 Correct 3 ms 5208 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 7 ms 4952 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 25 ms 5208 KB Output is correct
38 Correct 25 ms 5208 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 3 ms 5208 KB Output is correct
41 Correct 3 ms 5208 KB Output is correct
42 Correct 3 ms 5208 KB Output is correct
43 Execution timed out 3069 ms 5464 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 23 ms 5208 KB Output is correct
4 Correct 25 ms 5208 KB Output is correct
5 Correct 25 ms 5208 KB Output is correct
6 Correct 25 ms 5208 KB Output is correct
7 Correct 25 ms 5208 KB Output is correct
8 Correct 26 ms 4960 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 2 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 2 ms 5208 KB Output is correct
17 Correct 2 ms 5208 KB Output is correct
18 Correct 4 ms 5208 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 4 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 3 ms 5208 KB Output is correct
23 Correct 3 ms 5208 KB Output is correct
24 Correct 3 ms 5148 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5208 KB Output is correct
29 Correct 27 ms 5208 KB Output is correct
30 Correct 24 ms 5208 KB Output is correct
31 Correct 2 ms 5208 KB Output is correct
32 Correct 3 ms 5208 KB Output is correct
33 Correct 3 ms 5208 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 7 ms 4952 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 25 ms 5208 KB Output is correct
38 Correct 25 ms 5208 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 3 ms 5208 KB Output is correct
41 Correct 3 ms 5208 KB Output is correct
42 Correct 3 ms 5208 KB Output is correct
43 Correct 527 ms 8536 KB Output is correct
44 Correct 793 ms 12112 KB Output is correct
45 Correct 812 ms 12112 KB Output is correct
46 Correct 841 ms 12112 KB Output is correct
47 Execution timed out 3100 ms 8528 KB Time limit exceeded
48 Halted 0 ms 0 KB -