답안 #786382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786382 2023-07-18T07:18:34 Z ono_de206 디지털 회로 (IOI22_circuit) C++17
18 / 100
3000 ms 13292 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;
long long pp[mxn][2];
vector<long long> dp[mxn];
bool a[mxn];
vector<int> g[mxn];

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

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;
	}
}

int count_ways(int L, int R) {
	for(int i = L; i <= R; i++) {
		a[i] = a[i] ^ 1;
	}
	dfs(0);
	// 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:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for(int i = 1; i <= g[to].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 4 ms 9680 KB Output is correct
3 Correct 11 ms 9680 KB Output is correct
4 Correct 11 ms 9680 KB Output is correct
5 Correct 11 ms 9680 KB Output is correct
6 Correct 14 ms 9740 KB Output is correct
7 Correct 12 ms 9680 KB Output is correct
8 Correct 12 ms 9680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9704 KB Output is correct
2 Correct 5 ms 9728 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 5 ms 9660 KB Output is correct
5 Correct 5 ms 9680 KB Output is correct
6 Correct 5 ms 9680 KB Output is correct
7 Correct 5 ms 9808 KB Output is correct
8 Correct 5 ms 9680 KB Output is correct
9 Correct 5 ms 9680 KB Output is correct
10 Correct 5 ms 9808 KB Output is correct
11 Correct 5 ms 9808 KB Output is correct
12 Correct 5 ms 9680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 4 ms 9680 KB Output is correct
3 Correct 11 ms 9680 KB Output is correct
4 Correct 11 ms 9680 KB Output is correct
5 Correct 11 ms 9680 KB Output is correct
6 Correct 14 ms 9740 KB Output is correct
7 Correct 12 ms 9680 KB Output is correct
8 Correct 12 ms 9680 KB Output is correct
9 Correct 5 ms 9704 KB Output is correct
10 Correct 5 ms 9728 KB Output is correct
11 Correct 5 ms 9680 KB Output is correct
12 Correct 5 ms 9660 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 5 ms 9680 KB Output is correct
15 Correct 5 ms 9808 KB Output is correct
16 Correct 5 ms 9680 KB Output is correct
17 Correct 5 ms 9680 KB Output is correct
18 Correct 5 ms 9808 KB Output is correct
19 Correct 5 ms 9808 KB Output is correct
20 Correct 5 ms 9680 KB Output is correct
21 Correct 5 ms 9680 KB Output is correct
22 Correct 5 ms 9680 KB Output is correct
23 Correct 6 ms 9680 KB Output is correct
24 Correct 6 ms 9808 KB Output is correct
25 Correct 5 ms 9808 KB Output is correct
26 Correct 5 ms 9804 KB Output is correct
27 Correct 5 ms 9808 KB Output is correct
28 Correct 6 ms 9680 KB Output is correct
29 Correct 13 ms 9708 KB Output is correct
30 Correct 12 ms 9680 KB Output is correct
31 Correct 5 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 6 ms 9680 KB Output is correct
36 Correct 5 ms 9808 KB Output is correct
37 Correct 12 ms 9808 KB Output is correct
38 Correct 12 ms 9808 KB Output is correct
39 Correct 5 ms 9680 KB Output is correct
40 Correct 5 ms 9680 KB Output is correct
41 Correct 6 ms 9680 KB Output is correct
42 Correct 5 ms 9708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3008 ms 13292 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3008 ms 13292 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9704 KB Output is correct
2 Correct 5 ms 9728 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 5 ms 9660 KB Output is correct
5 Correct 5 ms 9680 KB Output is correct
6 Correct 5 ms 9680 KB Output is correct
7 Correct 5 ms 9808 KB Output is correct
8 Correct 5 ms 9680 KB Output is correct
9 Correct 5 ms 9680 KB Output is correct
10 Correct 5 ms 9808 KB Output is correct
11 Correct 5 ms 9808 KB Output is correct
12 Correct 5 ms 9680 KB Output is correct
13 Execution timed out 3008 ms 13292 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 4 ms 9680 KB Output is correct
3 Correct 11 ms 9680 KB Output is correct
4 Correct 11 ms 9680 KB Output is correct
5 Correct 11 ms 9680 KB Output is correct
6 Correct 14 ms 9740 KB Output is correct
7 Correct 12 ms 9680 KB Output is correct
8 Correct 12 ms 9680 KB Output is correct
9 Correct 5 ms 9704 KB Output is correct
10 Correct 5 ms 9728 KB Output is correct
11 Correct 5 ms 9680 KB Output is correct
12 Correct 5 ms 9660 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 5 ms 9680 KB Output is correct
15 Correct 5 ms 9808 KB Output is correct
16 Correct 5 ms 9680 KB Output is correct
17 Correct 5 ms 9680 KB Output is correct
18 Correct 5 ms 9808 KB Output is correct
19 Correct 5 ms 9808 KB Output is correct
20 Correct 5 ms 9680 KB Output is correct
21 Correct 5 ms 9680 KB Output is correct
22 Correct 5 ms 9680 KB Output is correct
23 Correct 6 ms 9680 KB Output is correct
24 Correct 6 ms 9808 KB Output is correct
25 Correct 5 ms 9808 KB Output is correct
26 Correct 5 ms 9804 KB Output is correct
27 Correct 5 ms 9808 KB Output is correct
28 Correct 6 ms 9680 KB Output is correct
29 Correct 13 ms 9708 KB Output is correct
30 Correct 12 ms 9680 KB Output is correct
31 Correct 5 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 6 ms 9680 KB Output is correct
36 Correct 5 ms 9808 KB Output is correct
37 Correct 12 ms 9808 KB Output is correct
38 Correct 12 ms 9808 KB Output is correct
39 Correct 5 ms 9680 KB Output is correct
40 Correct 5 ms 9680 KB Output is correct
41 Correct 6 ms 9680 KB Output is correct
42 Correct 5 ms 9708 KB Output is correct
43 Execution timed out 3024 ms 9936 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 4 ms 9680 KB Output is correct
3 Correct 11 ms 9680 KB Output is correct
4 Correct 11 ms 9680 KB Output is correct
5 Correct 11 ms 9680 KB Output is correct
6 Correct 14 ms 9740 KB Output is correct
7 Correct 12 ms 9680 KB Output is correct
8 Correct 12 ms 9680 KB Output is correct
9 Correct 5 ms 9704 KB Output is correct
10 Correct 5 ms 9728 KB Output is correct
11 Correct 5 ms 9680 KB Output is correct
12 Correct 5 ms 9660 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 5 ms 9680 KB Output is correct
15 Correct 5 ms 9808 KB Output is correct
16 Correct 5 ms 9680 KB Output is correct
17 Correct 5 ms 9680 KB Output is correct
18 Correct 5 ms 9808 KB Output is correct
19 Correct 5 ms 9808 KB Output is correct
20 Correct 5 ms 9680 KB Output is correct
21 Correct 5 ms 9680 KB Output is correct
22 Correct 5 ms 9680 KB Output is correct
23 Correct 6 ms 9680 KB Output is correct
24 Correct 6 ms 9808 KB Output is correct
25 Correct 5 ms 9808 KB Output is correct
26 Correct 5 ms 9804 KB Output is correct
27 Correct 5 ms 9808 KB Output is correct
28 Correct 6 ms 9680 KB Output is correct
29 Correct 13 ms 9708 KB Output is correct
30 Correct 12 ms 9680 KB Output is correct
31 Correct 5 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 6 ms 9680 KB Output is correct
36 Correct 5 ms 9808 KB Output is correct
37 Correct 12 ms 9808 KB Output is correct
38 Correct 12 ms 9808 KB Output is correct
39 Correct 5 ms 9680 KB Output is correct
40 Correct 5 ms 9680 KB Output is correct
41 Correct 6 ms 9680 KB Output is correct
42 Correct 5 ms 9708 KB Output is correct
43 Execution timed out 3008 ms 13292 KB Time limit exceeded
44 Halted 0 ms 0 KB -