답안 #1078069

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078069 2024-08-27T12:12:54 Z pcc 디지털 회로 (IOI22_circuit) C++17
18 / 100
3000 ms 8024 KB
#include "circuit.h"

#include <vector>
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second

const int mxn = 2e5+10;

const ll mod = 1000002022;

vector<int> tree[mxn];
int par[mxn];
int N,M;
ll dp[mxn][2];
ll tot = 1;

ll mad(ll a,ll b){
	a += b;
	return a>=mod?a-mod:a;
}
ll mub(ll a,ll b){
	return mad(a,mod-b);
}

pll calc(vector<ll>& a,vector<ll>& b){

	vector<ll> dp(a.size()+1,0);
	int s = a.size();
	dp[0] = a[0];
	dp[1] = b[0];
	for(int i = 1;i<s;i++){
		for(int j = i+1;j>=0;j--){
			dp[j] = dp[j]*a[i]%mod;
			if(j)dp[j] = mad(dp[j],dp[j-1]*b[i]%mod);
		}
	}
	for(int i = 1;i<=s;i++){
		dp[i] = mad(dp[i-1],dp[i]);
	}
	ll tot = mad(a[0],b[0]);
	for(int i = 1;i<a.size();i++)tot = tot*mad(a[i],b[i])%mod%mod;
	tot = tot*s%mod;
	pll re = pll(0,0);
	for(int c = 1;c<=s;c++){
		re.fs = mad(re.fs,dp[c-1]);
		re.sc = mad(re.sc,mub(dp[s],dp[c-1]));
	}
	assert(mad(re.fs,re.sc) == tot);
	/*
	cerr<<"CALC: "<<endl;
	for(auto &i:a)cerr<<i<<' ';cerr<<endl;
	for(auto &i:b)cerr<<i<<' ';cerr<<endl;
	for(auto &i:dp)cerr<<i<<' ';cerr<<endl;
	cerr<<re.fs<<','<<re.sc<<"::"<<tot<<endl;
	*/
	return re;
}

void dfs(int now){
	if(tree[now].empty())return;
	vector<ll> v1,v2;
	for(auto nxt:tree[now]){
		dfs(nxt);
		v1.push_back(dp[nxt][0]);
		v2.push_back(dp[nxt][1]);
	}
	auto [a,b] = calc(v1,v2);
	tot = tot*v1.size()%mod;
	assert(a<mod&&b<mod);
	dp[now][0] = a,dp[now][1] = b;
	//cerr<<now<<":"<<dp[now][0]<<' '<<dp[now][1]<<endl;
	return;
}

void init(int N1, int M1, std::vector<int> P, std::vector<int> A) {
	N = N1,M = M1;
	for(int i = 1;i<N+M;i++){
		par[i] = P[i];
		tree[par[i]].push_back(i);
	}
	for(int i = 0;i<M;i++){
		dp[i+N][A[i]] = 1;
	}
	dfs(0);
	//cerr<<"TOT: "<<tot<<endl;
	assert(tot == mad(dp[0][0],dp[0][1]));
	//for(int i = 0;i<N+M;i++)cerr<<dp[i][0]<<','<<dp[i][1]<<' ';cerr<<endl;
}

void update(int now){
	while(now != 0){
		now = par[now];
		vector<ll> v1,v2;
		for(auto nxt:tree[now]){
			v1.push_back(dp[nxt][0]);
			v2.push_back(dp[nxt][1]);
		}
		auto [a,b] = calc(v1,v2);
		dp[now][0] = a,dp[now][1] = b;
	}
	return;
}

int count_ways(int L, int R) {
	for(int i = L;i<=R;i++){
		dp[i][0] ^= 1;
		dp[i][1] ^= 1;
		//update(i);
	}
	dfs(0);
	//cerr<<"NOW: ";
	//for(int i = N;i<N+M;i++)cerr<<(dp[i][0]?0:1);cerr<<endl;
	return dp[0][1];
}

Compilation message

circuit.cpp: In function 'std::pair<long long int, long long int> calc(std::vector<long long int>&, std::vector<long long int>&)':
circuit.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for(int i = 1;i<a.size();i++)tot = tot*mad(a[i],b[i])%mod%mod;
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 11 ms 5208 KB Output is correct
4 Correct 12 ms 5208 KB Output is correct
5 Correct 12 ms 5212 KB Output is correct
6 Correct 13 ms 5208 KB Output is correct
7 Correct 14 ms 5208 KB Output is correct
8 Correct 12 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 4952 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 4 ms 4956 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 4 ms 5208 KB Output is correct
10 Correct 4 ms 5208 KB Output is correct
11 Correct 4 ms 5208 KB Output is correct
12 Correct 5 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 11 ms 5208 KB Output is correct
4 Correct 12 ms 5208 KB Output is correct
5 Correct 12 ms 5212 KB Output is correct
6 Correct 13 ms 5208 KB Output is correct
7 Correct 14 ms 5208 KB Output is correct
8 Correct 12 ms 5208 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 3 ms 4952 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 4 ms 4956 KB Output is correct
14 Correct 3 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 4 ms 5208 KB Output is correct
19 Correct 4 ms 5208 KB Output is correct
20 Correct 5 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 4 ms 5208 KB Output is correct
25 Correct 4 ms 5040 KB Output is correct
26 Correct 4 ms 5208 KB Output is correct
27 Correct 4 ms 5204 KB Output is correct
28 Correct 4 ms 5208 KB Output is correct
29 Correct 12 ms 5220 KB Output is correct
30 Correct 13 ms 5208 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 4 ms 5208 KB Output is correct
33 Correct 4 ms 5208 KB Output is correct
34 Correct 5 ms 4952 KB Output is correct
35 Correct 5 ms 4952 KB Output is correct
36 Correct 4 ms 5208 KB Output is correct
37 Correct 16 ms 5208 KB Output is correct
38 Correct 13 ms 5208 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 4 ms 5208 KB Output is correct
41 Correct 5 ms 4952 KB Output is correct
42 Correct 3 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3052 ms 8024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3052 ms 8024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 4952 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 4 ms 4956 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 4 ms 5208 KB Output is correct
10 Correct 4 ms 5208 KB Output is correct
11 Correct 4 ms 5208 KB Output is correct
12 Correct 5 ms 5208 KB Output is correct
13 Execution timed out 3052 ms 8024 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 11 ms 5208 KB Output is correct
4 Correct 12 ms 5208 KB Output is correct
5 Correct 12 ms 5212 KB Output is correct
6 Correct 13 ms 5208 KB Output is correct
7 Correct 14 ms 5208 KB Output is correct
8 Correct 12 ms 5208 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 3 ms 4952 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 4 ms 4956 KB Output is correct
14 Correct 3 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 4 ms 5208 KB Output is correct
19 Correct 4 ms 5208 KB Output is correct
20 Correct 5 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 4 ms 5208 KB Output is correct
25 Correct 4 ms 5040 KB Output is correct
26 Correct 4 ms 5208 KB Output is correct
27 Correct 4 ms 5204 KB Output is correct
28 Correct 4 ms 5208 KB Output is correct
29 Correct 12 ms 5220 KB Output is correct
30 Correct 13 ms 5208 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 4 ms 5208 KB Output is correct
33 Correct 4 ms 5208 KB Output is correct
34 Correct 5 ms 4952 KB Output is correct
35 Correct 5 ms 4952 KB Output is correct
36 Correct 4 ms 5208 KB Output is correct
37 Correct 16 ms 5208 KB Output is correct
38 Correct 13 ms 5208 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 4 ms 5208 KB Output is correct
41 Correct 5 ms 4952 KB Output is correct
42 Correct 3 ms 4952 KB Output is correct
43 Execution timed out 3047 ms 5208 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 11 ms 5208 KB Output is correct
4 Correct 12 ms 5208 KB Output is correct
5 Correct 12 ms 5212 KB Output is correct
6 Correct 13 ms 5208 KB Output is correct
7 Correct 14 ms 5208 KB Output is correct
8 Correct 12 ms 5208 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 3 ms 4952 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 4 ms 4956 KB Output is correct
14 Correct 3 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 4 ms 5208 KB Output is correct
19 Correct 4 ms 5208 KB Output is correct
20 Correct 5 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 4 ms 5208 KB Output is correct
25 Correct 4 ms 5040 KB Output is correct
26 Correct 4 ms 5208 KB Output is correct
27 Correct 4 ms 5204 KB Output is correct
28 Correct 4 ms 5208 KB Output is correct
29 Correct 12 ms 5220 KB Output is correct
30 Correct 13 ms 5208 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 4 ms 5208 KB Output is correct
33 Correct 4 ms 5208 KB Output is correct
34 Correct 5 ms 4952 KB Output is correct
35 Correct 5 ms 4952 KB Output is correct
36 Correct 4 ms 5208 KB Output is correct
37 Correct 16 ms 5208 KB Output is correct
38 Correct 13 ms 5208 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 4 ms 5208 KB Output is correct
41 Correct 5 ms 4952 KB Output is correct
42 Correct 3 ms 4952 KB Output is correct
43 Execution timed out 3052 ms 8024 KB Time limit exceeded
44 Halted 0 ms 0 KB -