답안 #639356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
639356 2022-09-09T15:57:36 Z CSQ31 디지털 회로 (IOI22_circuit) C++17
2 / 100
555 ms 5064 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD = 1000002022;
const int MAXN = 1e5+5;
vector<int>adj[MAXN];
ll c[MAXN];
int n,m,sub[MAXN];
void dfs(int v){
	if(adj[v].empty())sub[v] = 1;
	else sub[v] = adj[v].size();
	for(int x:adj[v]){
		dfs(x);
		sub[v] = sub[v]*sub[x]%MOD;
	}
	
}
void dfs(int v,ll cur){
	if(adj[v].empty()){
		c[v-n] = cur;
		return;
	}
	int s = adj[v].size();
	vector<ll>pref(s,1),suff(s,1);
	for(int i=0;i<s;i++){
		pref[i] = sub[adj[v][i]];
		suff[i] = sub[adj[v][i]];
		if(i)pref[i] = pref[i]*pref[i-1]%MOD;
	}
	for(int i=s-2;i>=0;i--)suff[i] = suff[i]*suff[i+1]%MOD;
	
	for(int i=0;i<s;i++){
		ll k = 1;
		if(i)k = pref[i-1]*k%MOD;
		if(i!=s-1)k = suff[i+1]*k%MOD;
		dfs(adj[v][i],(cur*k)%MOD);
		
	}
}
ll ans = 0;
vector<int>a;
void init(int N, int M, vector<int> p, vector<int> A) {
	n = N;
	m = M;
	a = A;
	for(int i=1;i<n+m;i++)adj[p[i]].push_back(i);
	dfs(0);
	dfs(0,1);
	for(int i=0;i<m;i++){
		if(a[i])ans+=c[i];
		ans%=MOD;
	}
	
}

int count_ways(int L, int R) {
	L-=n;
	R-=n;
	for(int i=L;i<=R;i++){
		if(!a[i])ans+=c[i];
		else ans+=MOD-c[i];
		a[i]^=1;
		ans%=MOD;
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Incorrect 1 ms 2640 KB 1st lines differ - on the 1st token, expected: '52130940', found: '971487268'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Incorrect 1 ms 2640 KB 1st lines differ - on the 1st token, expected: '52130940', found: '971487268'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 555 ms 5064 KB 1st lines differ - on the 1st token, expected: '431985922', found: '6570984'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 555 ms 5064 KB 1st lines differ - on the 1st token, expected: '431985922', found: '6570984'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Incorrect 1 ms 2640 KB 1st lines differ - on the 1st token, expected: '52130940', found: '971487268'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Incorrect 1 ms 2640 KB 1st lines differ - on the 1st token, expected: '52130940', found: '971487268'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 1 ms 2640 KB Output is correct
10 Incorrect 1 ms 2640 KB 1st lines differ - on the 1st token, expected: '52130940', found: '971487268'
11 Halted 0 ms 0 KB -