답안 #638242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638242 2022-09-05T05:54:52 Z jamezzz 디지털 회로 (IOI22_circuit) C++17
0 / 100
3000 ms 30848 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define maxn 100005
#define mod 1000002022

int N,M,ways[maxn][2],pfx[maxn];
vector<int> A,AL[maxn];
vector<vector<ll>> memo[maxn];

void init(int _N,int _M,vector<int> P,vector<int> _A){
	N=_N,M=_M;
	for(int i=0;i<N;++i)A.push_back(0);
	for(int i=N;i<N+M;++i){
		A.push_back(_A[i-N]);
		ways[i][0]=(A[i]==0);
		ways[i][1]=(A[i]==1);
	}
	for(int i=0;i<N+M;++i){
		AL[P[i]].push_back(i);
	}
	for(int i=0;i<N;++i){
		memo[i].resize(AL[i].size()+5);
		for(int j=0;j<AL[i].size()+5;++j){
			memo[i][j].resize(AL[i].size()+1+5);
		}
	}
}

int dp(int u){
	int n=AL[u].size();
	for(int i=0;i<n;++i){
		int v=AL[u][i];
		if(v<N)dp(v);
		if(i==0){
			for(int j=0;j<=n;++j){
				memo[u][i][j]=0;
			}
			memo[u][i][0]=ways[v][0];
			memo[u][i][1]=ways[v][1];
		}
		else{
			for(int j=0;j<=n;++j){
				memo[u][i][j]=(memo[u][i-1][j]*ways[v][0])%mod;
				if(j!=0){
					memo[u][i][j]+=(memo[u][i-1][j-1]*ways[v][1])%mod;
					memo[u][i][j]%=mod;
				}
			}
		}
	}
	ways[u][0]=ways[u][1]=0;
	for(int i=0;i<=n;++i){
		if(i==0)pfx[i]=memo[u][n-1][i];
		else pfx[i]=pfx[i-1]+memo[u][n-1][i];
		pfx[i]%=mod;
	}
	for(int i=1;i<=n;++i){//if p=i
		ways[u][0]+=pfx[i-1];
		ways[u][1]+=pfx[n]-pfx[i-1]+mod;
		ways[u][0]%=mod;
		ways[u][1]%=mod;
	}
	return ways[u][1];
}

int count_ways(int L,int R){
	for(int i=L;i<=R;++i){
		A[i]=1-A[i];
		swap(ways[i][0],ways[i][1]);
	}
	return dp(0);
}

Compilation message

circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:27:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for(int j=0;j<AL[i].size()+5;++j){
      |               ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 9936 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 9936 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 9936 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3027 ms 30848 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3027 ms 30848 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 9936 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 9936 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 9936 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -