답안 #1078119

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078119 2024-08-27T12:56:01 Z pcc 디지털 회로 (IOI22_circuit) C++17
2 / 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];
int sz[mxn];
ll arr[mxn];

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);
}

ll pw(ll a,ll b){
	ll re = 1;
	while(b){
		if(b&1)re = re*a%mod;
		b>>=1;
		a = a*a%mod;
	}
	return re;
}

void dfs(int now){
	dp[now] = sz[now] = 1;
	for(auto nxt:tree[now]){
		dfs(nxt);
		sz[now] = sz[nxt]*sz[now]%mod;
	}
	if(tree[now].size())sz[now] = sz[now]*tree[now].size()%mod;
	return;
}

void dfs1(int now){
	ll sum = 0;
	vector<ll> suf;
	for(auto nxt:tree[now]){
		suf.push_back(sz[nxt]);
	}
	suf.push_back(1);
	for(int i = (int)suf.size()-2;i>=0;i--)suf[i] = suf[i+1]*suf[i]%mod;
	ll pref = 1;
	for(int i = 0;i<tree[now].size();i++){
		int nxt = tree[now][i];
		ll ts = pref*suf[i+1];
		dp[nxt] = dp[now]*ts%mod;
		pref = pref*sz[nxt]%mod;
		dfs1(nxt);
	}
	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++){
		arr[i+N] = A[i];
	}
	dfs(0);
	dfs1(0);
	/*
	cerr<<"SZ: ";
	for(int i = 0;i<N+M;i++)cerr<<sz[i]<<' ';cerr<<endl;
	cerr<<"DP: ";
	for(int i = 0;i<N+M;i++)cerr<<dp[i]<<' ';cerr<<endl;
	*/
	//for(int i = 0;i<N+M;i++)cerr<<dp[i][0]<<','<<dp[i][1]<<' ';cerr<<endl;
}

int count_ways(int L, int R) {
	for(int i = L;i<=R;i++){
		arr[i] ^= 1;
	}
	//cerr<<"NOW: ";for(int i = N;i<N+M;i++)cerr<<arr[i]<<' ';cerr<<endl;
	ll ans = 0;
	for(int i = N;i<N+M;i++)ans = mad(ans,dp[i]*arr[i]%mod);
	return ans;
	//dfs(0);
	//cerr<<"NOW: ";
	//for(int i = N;i<N+M;i++)cerr<<(dp[i][0]?0:1);cerr<<endl;
}

Compilation message

circuit.cpp: In function 'void dfs1(int)':
circuit.cpp:61:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i = 0;i<tree[now].size();i++){
      |                ~^~~~~~~~~~~~~~~~~
circuit.cpp:53:5: warning: unused variable 'sum' [-Wunused-variable]
   53 |  ll sum = 0;
      |     ^~~
# 결과 실행 시간 메모리 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 5208 KB Output is correct
5 Correct 2 ms 5000 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Incorrect 2 ms 4952 KB 1st lines differ - on the 1st token, expected: '52130940', found: '218061342'
3 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 2 ms 4952 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 2 ms 5000 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Incorrect 2 ms 4952 KB 1st lines differ - on the 1st token, expected: '52130940', found: '218061342'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3059 ms 8024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3059 ms 8024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Incorrect 2 ms 4952 KB 1st lines differ - on the 1st token, expected: '52130940', found: '218061342'
3 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 2 ms 4952 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 2 ms 5000 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Incorrect 2 ms 4952 KB 1st lines differ - on the 1st token, expected: '52130940', found: '218061342'
11 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 2 ms 4952 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 2 ms 5000 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Incorrect 2 ms 4952 KB 1st lines differ - on the 1st token, expected: '52130940', found: '218061342'
11 Halted 0 ms 0 KB -