답안 #786404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786404 2023-07-18T07:25:49 Z ono_de206 디지털 회로 (IOI22_circuit) C++17
22 / 100
3000 ms 17940 KB
#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;

#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

//#define int long long
 
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int mxn = 2e5 + 10;
const long long mod = 1000002022;
int n, m, par[mxn];
long long pp[mxn][2];
vector<long long> dp[mxn];
bool a[mxn];
vector<int> g[mxn];

void dfs(int to) {
	pp[to][0] = pp[to][1] = 0;
	if(to >= n) {
		if(a[to]) pp[to][1] = 1;
		else pp[to][0] = 1;
		return;
	}
	dp[to].clear();
	dp[to].resize(g[to].size() + 1);
	dp[to][0] = 1;
	for(int x : g[to]) {
		dfs(x);
		for(int j = g[to].size(); j > 0; j--) {
			dp[to][j] = ((dp[to][j] * pp[x][0]) + (dp[to][j - 1] * pp[x][1])) % mod;
		}
		dp[to][0] = (dp[to][0] * pp[x][0]) % mod;
	}
	pp[to][0] = (dp[to][0] * (long long)g[to].size()) % mod;
	for(int i = 1; i <= g[to].size(); i++) {
		pp[to][1] = (pp[to][1] + dp[to][i] * (long long)i) % mod;
		pp[to][0] = (pp[to][0] + dp[to][i] * (long long)(g[to].size() - i)) % mod;
	}
}

void dfsup(int to) {
	pp[to][0] = pp[to][1] = 0;
	if(to >= n) {
		if(a[to]) pp[to][1] = 1;
		else pp[to][0] = 1;
		dfsup(par[to]);
		return;
	}
	dp[to].clear();
	dp[to].resize(g[to].size() + 1);
	dp[to][0] = 1;
	for(int x : g[to]) {
		for(int j = g[to].size(); j > 0; j--) {
			dp[to][j] = ((dp[to][j] * pp[x][0]) + (dp[to][j - 1] * pp[x][1])) % mod;
		}
		dp[to][0] = (dp[to][0] * pp[x][0]) % mod;
	}
	pp[to][0] = (dp[to][0] * (long long)g[to].size()) % mod;
	for(int i = 1; i <= g[to].size(); i++) {
		pp[to][1] = (pp[to][1] + dp[to][i] * (long long)i) % mod;
		pp[to][0] = (pp[to][0] + dp[to][i] * (long long)(g[to].size() - i)) % mod;
	}
	if(to) dfsup(par[to]);
}

void init(int n, int m, vector<int> p, vector<int> a) {
	::n = n;
	::m = m;
	par[0] = -1;
	for(int i = 1; i < n + m; i++) {
		g[p[i]].pb(i);
		par[i] = p[i];
	}
	for(int i = 0; i < m; i++) {
		::a[i + n] = a[i];
	}
	dfs(0);
}

int count_ways(int L, int R) {
	for(int i = L; i <= R; i++) {
		a[i] = a[i] ^ 1;
	}
	if(L < R) dfs(0);
	else dfsup(L);
	// cout << pp[0][1] << '\n';
	// for(int i = 0; i < n + m; i++) {
	// 	cout << pp[i][0] << ' ' << pp[i][1] << '\n';
	// }
	// cout << " sus \n";
	return pp[0][1];
}

Compilation message

circuit.cpp: In function 'void dfs(int)':
circuit.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for(int i = 1; i <= g[to].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~
circuit.cpp: In function 'void dfsup(int)':
circuit.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |  for(int i = 1; i <= g[to].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 4 ms 9680 KB Output is correct
3 Correct 12 ms 9680 KB Output is correct
4 Correct 13 ms 9680 KB Output is correct
5 Correct 13 ms 9680 KB Output is correct
6 Correct 13 ms 9680 KB Output is correct
7 Correct 13 ms 9680 KB Output is correct
8 Correct 13 ms 9732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 4 ms 9692 KB Output is correct
3 Correct 4 ms 9680 KB Output is correct
4 Correct 5 ms 9672 KB Output is correct
5 Correct 5 ms 9680 KB Output is correct
6 Correct 6 ms 9708 KB Output is correct
7 Correct 5 ms 9808 KB Output is correct
8 Correct 5 ms 9808 KB Output is correct
9 Correct 5 ms 9808 KB Output is correct
10 Correct 5 ms 9808 KB Output is correct
11 Correct 5 ms 9808 KB Output is correct
12 Correct 4 ms 9808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 4 ms 9680 KB Output is correct
3 Correct 12 ms 9680 KB Output is correct
4 Correct 13 ms 9680 KB Output is correct
5 Correct 13 ms 9680 KB Output is correct
6 Correct 13 ms 9680 KB Output is correct
7 Correct 13 ms 9680 KB Output is correct
8 Correct 13 ms 9732 KB Output is correct
9 Correct 4 ms 9680 KB Output is correct
10 Correct 4 ms 9692 KB Output is correct
11 Correct 4 ms 9680 KB Output is correct
12 Correct 5 ms 9672 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 6 ms 9708 KB Output is correct
15 Correct 5 ms 9808 KB Output is correct
16 Correct 5 ms 9808 KB Output is correct
17 Correct 5 ms 9808 KB Output is correct
18 Correct 5 ms 9808 KB Output is correct
19 Correct 5 ms 9808 KB Output is correct
20 Correct 4 ms 9808 KB Output is correct
21 Correct 5 ms 9808 KB Output is correct
22 Correct 5 ms 9704 KB Output is correct
23 Correct 5 ms 9680 KB Output is correct
24 Correct 5 ms 9808 KB Output is correct
25 Correct 5 ms 9808 KB Output is correct
26 Correct 5 ms 9764 KB Output is correct
27 Correct 6 ms 9808 KB Output is correct
28 Correct 5 ms 9808 KB Output is correct
29 Correct 12 ms 9680 KB Output is correct
30 Correct 17 ms 9764 KB Output is correct
31 Correct 6 ms 9808 KB Output is correct
32 Correct 5 ms 9808 KB Output is correct
33 Correct 5 ms 9680 KB Output is correct
34 Correct 5 ms 9680 KB Output is correct
35 Correct 7 ms 9680 KB Output is correct
36 Correct 5 ms 9808 KB Output is correct
37 Correct 13 ms 9932 KB Output is correct
38 Correct 13 ms 9940 KB Output is correct
39 Correct 5 ms 9680 KB Output is correct
40 Correct 5 ms 9732 KB Output is correct
41 Correct 4 ms 9680 KB Output is correct
42 Correct 5 ms 9680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 673 ms 13896 KB Output is correct
2 Correct 824 ms 17904 KB Output is correct
3 Correct 852 ms 17940 KB Output is correct
4 Correct 873 ms 17876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 673 ms 13896 KB Output is correct
2 Correct 824 ms 17904 KB Output is correct
3 Correct 852 ms 17940 KB Output is correct
4 Correct 873 ms 17876 KB Output is correct
5 Execution timed out 3065 ms 13800 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 4 ms 9692 KB Output is correct
3 Correct 4 ms 9680 KB Output is correct
4 Correct 5 ms 9672 KB Output is correct
5 Correct 5 ms 9680 KB Output is correct
6 Correct 6 ms 9708 KB Output is correct
7 Correct 5 ms 9808 KB Output is correct
8 Correct 5 ms 9808 KB Output is correct
9 Correct 5 ms 9808 KB Output is correct
10 Correct 5 ms 9808 KB Output is correct
11 Correct 5 ms 9808 KB Output is correct
12 Correct 4 ms 9808 KB Output is correct
13 Correct 673 ms 13896 KB Output is correct
14 Correct 824 ms 17904 KB Output is correct
15 Correct 852 ms 17940 KB Output is correct
16 Correct 873 ms 17876 KB Output is correct
17 Execution timed out 3065 ms 13800 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 4 ms 9680 KB Output is correct
3 Correct 12 ms 9680 KB Output is correct
4 Correct 13 ms 9680 KB Output is correct
5 Correct 13 ms 9680 KB Output is correct
6 Correct 13 ms 9680 KB Output is correct
7 Correct 13 ms 9680 KB Output is correct
8 Correct 13 ms 9732 KB Output is correct
9 Correct 4 ms 9680 KB Output is correct
10 Correct 4 ms 9692 KB Output is correct
11 Correct 4 ms 9680 KB Output is correct
12 Correct 5 ms 9672 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 6 ms 9708 KB Output is correct
15 Correct 5 ms 9808 KB Output is correct
16 Correct 5 ms 9808 KB Output is correct
17 Correct 5 ms 9808 KB Output is correct
18 Correct 5 ms 9808 KB Output is correct
19 Correct 5 ms 9808 KB Output is correct
20 Correct 4 ms 9808 KB Output is correct
21 Correct 5 ms 9808 KB Output is correct
22 Correct 5 ms 9704 KB Output is correct
23 Correct 5 ms 9680 KB Output is correct
24 Correct 5 ms 9808 KB Output is correct
25 Correct 5 ms 9808 KB Output is correct
26 Correct 5 ms 9764 KB Output is correct
27 Correct 6 ms 9808 KB Output is correct
28 Correct 5 ms 9808 KB Output is correct
29 Correct 12 ms 9680 KB Output is correct
30 Correct 17 ms 9764 KB Output is correct
31 Correct 6 ms 9808 KB Output is correct
32 Correct 5 ms 9808 KB Output is correct
33 Correct 5 ms 9680 KB Output is correct
34 Correct 5 ms 9680 KB Output is correct
35 Correct 7 ms 9680 KB Output is correct
36 Correct 5 ms 9808 KB Output is correct
37 Correct 13 ms 9932 KB Output is correct
38 Correct 13 ms 9940 KB Output is correct
39 Correct 5 ms 9680 KB Output is correct
40 Correct 5 ms 9732 KB Output is correct
41 Correct 4 ms 9680 KB Output is correct
42 Correct 5 ms 9680 KB Output is correct
43 Execution timed out 3022 ms 10064 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 4 ms 9680 KB Output is correct
3 Correct 12 ms 9680 KB Output is correct
4 Correct 13 ms 9680 KB Output is correct
5 Correct 13 ms 9680 KB Output is correct
6 Correct 13 ms 9680 KB Output is correct
7 Correct 13 ms 9680 KB Output is correct
8 Correct 13 ms 9732 KB Output is correct
9 Correct 4 ms 9680 KB Output is correct
10 Correct 4 ms 9692 KB Output is correct
11 Correct 4 ms 9680 KB Output is correct
12 Correct 5 ms 9672 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 6 ms 9708 KB Output is correct
15 Correct 5 ms 9808 KB Output is correct
16 Correct 5 ms 9808 KB Output is correct
17 Correct 5 ms 9808 KB Output is correct
18 Correct 5 ms 9808 KB Output is correct
19 Correct 5 ms 9808 KB Output is correct
20 Correct 4 ms 9808 KB Output is correct
21 Correct 5 ms 9808 KB Output is correct
22 Correct 5 ms 9704 KB Output is correct
23 Correct 5 ms 9680 KB Output is correct
24 Correct 5 ms 9808 KB Output is correct
25 Correct 5 ms 9808 KB Output is correct
26 Correct 5 ms 9764 KB Output is correct
27 Correct 6 ms 9808 KB Output is correct
28 Correct 5 ms 9808 KB Output is correct
29 Correct 12 ms 9680 KB Output is correct
30 Correct 17 ms 9764 KB Output is correct
31 Correct 6 ms 9808 KB Output is correct
32 Correct 5 ms 9808 KB Output is correct
33 Correct 5 ms 9680 KB Output is correct
34 Correct 5 ms 9680 KB Output is correct
35 Correct 7 ms 9680 KB Output is correct
36 Correct 5 ms 9808 KB Output is correct
37 Correct 13 ms 9932 KB Output is correct
38 Correct 13 ms 9940 KB Output is correct
39 Correct 5 ms 9680 KB Output is correct
40 Correct 5 ms 9732 KB Output is correct
41 Correct 4 ms 9680 KB Output is correct
42 Correct 5 ms 9680 KB Output is correct
43 Correct 673 ms 13896 KB Output is correct
44 Correct 824 ms 17904 KB Output is correct
45 Correct 852 ms 17940 KB Output is correct
46 Correct 873 ms 17876 KB Output is correct
47 Execution timed out 3065 ms 13800 KB Time limit exceeded
48 Halted 0 ms 0 KB -