Submission #786383

# Submission time Handle Problem Language Result Execution time Memory
786383 2023-07-18T07:18:53 Z vjudge1 Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 13168 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++) {
      |                 ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 13 ms 9680 KB Output is correct
4 Correct 13 ms 9680 KB Output is correct
5 Correct 14 ms 9680 KB Output is correct
6 Correct 11 ms 9680 KB Output is correct
7 Correct 14 ms 9680 KB Output is correct
8 Correct 12 ms 9680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 4 ms 9680 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 4 ms 9680 KB Output is correct
5 Correct 5 ms 9680 KB Output is correct
6 Correct 4 ms 9648 KB Output is correct
7 Correct 6 ms 9680 KB Output is correct
8 Correct 6 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 5 ms 9680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 13 ms 9680 KB Output is correct
4 Correct 13 ms 9680 KB Output is correct
5 Correct 14 ms 9680 KB Output is correct
6 Correct 11 ms 9680 KB Output is correct
7 Correct 14 ms 9680 KB Output is correct
8 Correct 12 ms 9680 KB Output is correct
9 Correct 4 ms 9680 KB Output is correct
10 Correct 4 ms 9680 KB Output is correct
11 Correct 5 ms 9680 KB Output is correct
12 Correct 4 ms 9680 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 4 ms 9648 KB Output is correct
15 Correct 6 ms 9680 KB Output is correct
16 Correct 6 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 5 ms 9680 KB Output is correct
21 Correct 5 ms 9692 KB Output is correct
22 Correct 5 ms 9680 KB Output is correct
23 Correct 6 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 9808 KB Output is correct
27 Correct 5 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 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 6 ms 9808 KB Output is correct
37 Correct 13 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 5 ms 9680 KB Output is correct
42 Correct 5 ms 9680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3009 ms 13168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3009 ms 13168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9680 KB Output is correct
2 Correct 4 ms 9680 KB Output is correct
3 Correct 5 ms 9680 KB Output is correct
4 Correct 4 ms 9680 KB Output is correct
5 Correct 5 ms 9680 KB Output is correct
6 Correct 4 ms 9648 KB Output is correct
7 Correct 6 ms 9680 KB Output is correct
8 Correct 6 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 5 ms 9680 KB Output is correct
13 Execution timed out 3009 ms 13168 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 13 ms 9680 KB Output is correct
4 Correct 13 ms 9680 KB Output is correct
5 Correct 14 ms 9680 KB Output is correct
6 Correct 11 ms 9680 KB Output is correct
7 Correct 14 ms 9680 KB Output is correct
8 Correct 12 ms 9680 KB Output is correct
9 Correct 4 ms 9680 KB Output is correct
10 Correct 4 ms 9680 KB Output is correct
11 Correct 5 ms 9680 KB Output is correct
12 Correct 4 ms 9680 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 4 ms 9648 KB Output is correct
15 Correct 6 ms 9680 KB Output is correct
16 Correct 6 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 5 ms 9680 KB Output is correct
21 Correct 5 ms 9692 KB Output is correct
22 Correct 5 ms 9680 KB Output is correct
23 Correct 6 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 9808 KB Output is correct
27 Correct 5 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 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 6 ms 9808 KB Output is correct
37 Correct 13 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 5 ms 9680 KB Output is correct
42 Correct 5 ms 9680 KB Output is correct
43 Execution timed out 3097 ms 9936 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9680 KB Output is correct
2 Correct 5 ms 9680 KB Output is correct
3 Correct 13 ms 9680 KB Output is correct
4 Correct 13 ms 9680 KB Output is correct
5 Correct 14 ms 9680 KB Output is correct
6 Correct 11 ms 9680 KB Output is correct
7 Correct 14 ms 9680 KB Output is correct
8 Correct 12 ms 9680 KB Output is correct
9 Correct 4 ms 9680 KB Output is correct
10 Correct 4 ms 9680 KB Output is correct
11 Correct 5 ms 9680 KB Output is correct
12 Correct 4 ms 9680 KB Output is correct
13 Correct 5 ms 9680 KB Output is correct
14 Correct 4 ms 9648 KB Output is correct
15 Correct 6 ms 9680 KB Output is correct
16 Correct 6 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 5 ms 9680 KB Output is correct
21 Correct 5 ms 9692 KB Output is correct
22 Correct 5 ms 9680 KB Output is correct
23 Correct 6 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 9808 KB Output is correct
27 Correct 5 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 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 6 ms 9808 KB Output is correct
37 Correct 13 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 5 ms 9680 KB Output is correct
42 Correct 5 ms 9680 KB Output is correct
43 Execution timed out 3009 ms 13168 KB Time limit exceeded
44 Halted 0 ms 0 KB -