답안 #1058016

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058016 2024-08-14T08:00:18 Z tolbi 디지털 회로 (IOI22_circuit) C++17
18 / 100
3000 ms 3160 KB
#include "circuit.h"

#include <bits/stdc++.h>
using namespace std;

constexpr int MOD = 1e9+2022;
vector<vector<int>> arr;
int N,M,P;
array<int,2> dp[200023];
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
	::N=N,::M=M;
	arr.resize(N);
	for (int i = 1; i < N+M; i++){
		arr[P[i]].push_back(i);
	}
	for (int i = N; i < N+M; i++){
		dp[i][A[i-N]]=1;
		dp[i][A[i-N]^1]=0;
	}
}

int count_ways(int L, int R) {
	for (int i = L; i <= R; i++){
		swap(dp[i][0],dp[i][1]);
	}
	for (int i = N-1; i >= 0; i--){
		vector<int> curdp(1,0);
		curdp[0]=1;
		for (int j = 0; j < arr[i].size(); j++){
			vector<int> ndp(curdp.size()+1);
			for (int k = 0; k < ndp.size(); k++){
				if (k!=0){
					ndp[k]=(1ll*curdp[k-1]*dp[arr[i][j]][1])%MOD;
					if (ndp[k]>=MOD) ndp[k]-=MOD;
				}
				if (k!=curdp.size()){
					ndp[k]+=(1ll*curdp[k]*dp[arr[i][j]][0])%MOD;
					if (ndp[k]>=MOD) ndp[k]-=MOD;
				}
			}
			swap(ndp,curdp);
		}
		dp[i][0]=dp[i][1]=0;
		for (int j = 0; j < curdp.size(); j++){
			dp[i][0]+=(1ll*(arr[i].size()-j)*curdp[j])%MOD;
			dp[i][1]+=(1ll*j*curdp[j])%MOD;
			if (dp[i][0]>=MOD) dp[i][0]-=MOD;
			if (dp[i][1]>=MOD) dp[i][1]-=MOD;
		}
	}
	return dp[0][1];
}

Compilation message

circuit.cpp: In function 'int count_ways(int, int)':
circuit.cpp:29:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for (int j = 0; j < arr[i].size(); j++){
      |                   ~~^~~~~~~~~~~~~~~
circuit.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |    for (int k = 0; k < ndp.size(); k++){
      |                    ~~^~~~~~~~~~~~
circuit.cpp:36:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     if (k!=curdp.size()){
      |         ~^~~~~~~~~~~~~~
circuit.cpp:44:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for (int j = 0; j < curdp.size(); j++){
      |                   ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 9 ms 344 KB Output is correct
4 Correct 9 ms 344 KB Output is correct
5 Correct 9 ms 344 KB Output is correct
6 Correct 10 ms 528 KB Output is correct
7 Correct 9 ms 344 KB Output is correct
8 Correct 9 ms 532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 9 ms 344 KB Output is correct
4 Correct 9 ms 344 KB Output is correct
5 Correct 9 ms 344 KB Output is correct
6 Correct 10 ms 528 KB Output is correct
7 Correct 9 ms 344 KB Output is correct
8 Correct 9 ms 532 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 452 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 448 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 10 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 2 ms 508 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 10 ms 600 KB Output is correct
38 Correct 10 ms 600 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3020 ms 3160 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3020 ms 3160 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Execution timed out 3020 ms 3160 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 9 ms 344 KB Output is correct
4 Correct 9 ms 344 KB Output is correct
5 Correct 9 ms 344 KB Output is correct
6 Correct 10 ms 528 KB Output is correct
7 Correct 9 ms 344 KB Output is correct
8 Correct 9 ms 532 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 452 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 448 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 10 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 2 ms 508 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 10 ms 600 KB Output is correct
38 Correct 10 ms 600 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Execution timed out 3079 ms 600 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 9 ms 344 KB Output is correct
4 Correct 9 ms 344 KB Output is correct
5 Correct 9 ms 344 KB Output is correct
6 Correct 10 ms 528 KB Output is correct
7 Correct 9 ms 344 KB Output is correct
8 Correct 9 ms 532 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 452 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 448 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 10 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 2 ms 508 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 10 ms 600 KB Output is correct
38 Correct 10 ms 600 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Execution timed out 3020 ms 3160 KB Time limit exceeded
44 Halted 0 ms 0 KB -