답안 #1077308

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077308 2024-08-27T05:08:31 Z Muhammad_Aneeq 디지털 회로 (IOI22_circuit) C++17
0 / 100
516 ms 7868 KB
#include <vector>
using namespace std;
int const MAXN=2e5+10,mod=1e9+2022;
vector<int>nei[MAXN]={};
long long comp[2][MAXN]={};
int p[MAXN]={};
bool state[MAXN]={};
void calc(int x)
{
	vector<int>z=nei[x];
	comp[0][x]=comp[1][x]=0;
	for (int i=0;i<(1<<z.size());i++)
	{
		int cnt=0;
		long long pro=1;
		for (int j=0;j<z.size();j++)
		{
			if ((1<<j)&i)
			{
				cnt++;
				pro=(pro*comp[1][z[j]])%mod;
			}
			else
				pro=(pro*comp[0][z[j]])%mod;
		}
		comp[1][x]+=cnt*pro;
		if (cnt<z.size()/2)
			comp[0][x]+=(z.size()-cnt)*pro;
		comp[1][x]%=mod;
		comp[0][x]%=mod;
	}
}
void build(int x)
{
	for (auto i:nei[x])
		build(i);
	if (nei[x].size())
		calc(x);
}
void up(int x)
{
	if (x==-1)
		return;
	calc(x);
	up(p[x]);
}
void init(int N, int M,vector<int> P,vector<int> A)
{
	p[0]=-1;
	for (int i=1;i<N+M;i++)
	{
		p[i]=P[i];
		nei[P[i]].push_back(i);
	}
	for (int i=0;i<M;i++)
	{
		state[N+i]=A[i];
		comp[A[i]][N+i]=1;
		comp[1-A[i]][N+i]=0;
	}
}
int count_ways(int L, int R)
{
	for (int i=L;i<=R;i++)
	{
		state[i]^=1;
		comp[0][i]^=1;
		comp[1][i]^=1;
	}
	if (L==R)
		up(L);
	else
		build(0);
	return comp[1][0];
}

Compilation message

circuit.cpp: In function 'void calc(int)':
circuit.cpp:16:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   for (int j=0;j<z.size();j++)
      |                ~^~~~~~~~~
circuit.cpp:27:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   if (cnt<z.size()/2)
      |       ~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4952 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4952 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4952 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 516 ms 7868 KB 1st lines differ - on the 1st token, expected: '431985922', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 516 ms 7868 KB 1st lines differ - on the 1st token, expected: '431985922', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4952 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4952 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4952 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -