답안 #638243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638243 2022-09-05T05:57:22 Z jamezzz 디지털 회로 (IOI22_circuit) C++17
2 / 100
3000 ms 12908 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=1;i<N+M;++i){
		AL[P[i]].push_back(i);
	}
	for(int i=0;i<N;++i){
		memo[i].resize(AL[i].size());
		for(int j=0;j<AL[i].size();++j){
			memo[i][j].resize(AL[i].size()+1);
		}
	}
}

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();++j){
      |               ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 27 ms 12476 KB Output is correct
4 Correct 32 ms 12880 KB Output is correct
5 Correct 27 ms 12908 KB Output is correct
6 Correct 28 ms 12896 KB Output is correct
7 Correct 28 ms 12880 KB Output is correct
8 Correct 27 ms 12904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Incorrect 5 ms 5080 KB 1st lines differ - on the 1st token, expected: '655368480', found: '506157900'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 27 ms 12476 KB Output is correct
4 Correct 32 ms 12880 KB Output is correct
5 Correct 27 ms 12908 KB Output is correct
6 Correct 28 ms 12896 KB Output is correct
7 Correct 28 ms 12880 KB Output is correct
8 Correct 27 ms 12904 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Incorrect 5 ms 5080 KB 1st lines differ - on the 1st token, expected: '655368480', found: '506157900'
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3092 ms 11412 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3092 ms 11412 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Incorrect 5 ms 5080 KB 1st lines differ - on the 1st token, expected: '655368480', found: '506157900'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 27 ms 12476 KB Output is correct
4 Correct 32 ms 12880 KB Output is correct
5 Correct 27 ms 12908 KB Output is correct
6 Correct 28 ms 12896 KB Output is correct
7 Correct 28 ms 12880 KB Output is correct
8 Correct 27 ms 12904 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Incorrect 5 ms 5080 KB 1st lines differ - on the 1st token, expected: '655368480', found: '506157900'
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 27 ms 12476 KB Output is correct
4 Correct 32 ms 12880 KB Output is correct
5 Correct 27 ms 12908 KB Output is correct
6 Correct 28 ms 12896 KB Output is correct
7 Correct 28 ms 12880 KB Output is correct
8 Correct 27 ms 12904 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Incorrect 5 ms 5080 KB 1st lines differ - on the 1st token, expected: '655368480', found: '506157900'
12 Halted 0 ms 0 KB -