답안 #835020

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
835020 2023-08-23T06:00:05 Z pavement 디지털 회로 (IOI22_circuit) C++17
22 / 100
3000 ms 8784 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

using ll = long long;

const int MOD = (int)1e9 + 2022;
int N, M;
vector<int> A, P, tot_mem, dp_mem;
vector<vector<int> > adj;

int tot(int u) {
	if (tot_mem[u] != -1) {
		return tot_mem[u];
	}
	if (u >= N) {
		return tot_mem[u] = 1;
	}
	int ret = (int)(adj[u].size());
	for (auto v : adj[u]) {
		ret = ((ll)ret * (ll)tot(v)) % MOD;
	}
	return tot_mem[u] = ret;
}

int dp(int u) {
	if (dp_mem[u] != -1) {
		return dp_mem[u];
	}
	if (u >= N) {
		return dp_mem[u] = A[u - N];
	}
	vector<int> sub_dp((int)adj[u].size() + 1, 0);
	sub_dp[0] = 1;
	for (auto v : adj[u]) {
		vector<int> new_sub_dp((int)adj[u].size() + 1);
		for (int i = 0; i <= (int)adj[u].size(); i++) {
			new_sub_dp[i] = ((i ? (ll)sub_dp[i - 1] * dp(v) : 0ll) % MOD + (ll)sub_dp[i] * ((ll)tot(v) - dp(v)) % MOD) % MOD;
			if (new_sub_dp[i] < 0) {
				new_sub_dp[i] += MOD;
			}
		}
		sub_dp = new_sub_dp;
	}
	int ret = 0;
	for (int i = 0; i <= (int)adj[u].size(); i++) {
		ret = (ret + (ll)i * sub_dp[i] % MOD) % MOD;
	}
	return dp_mem[u] = ret;
}

void init(int N, int M, vector<int> P, vector<int> A) {
	::N = N;
	::M = M;
	::P = P;
	::A = A;
	adj.resize(N + M);
	tot_mem = dp_mem = vector<int>(N + M, -1);
	for (int i = 1; i < N + M; i++) {
		adj[P[i]].pb(i);
	}
}

int count_ways(int L, int R) {
	for (int i = L - N; i <= R - N; i++) {
		A[i] = !A[i];
	}
	
	for (int i = L; i <= R; i++) {
		for (int u = i; u != -1 && dp_mem[u] != -1; u = P[u]) {
			dp_mem[u] = -1;
		}
	}
	
	return dp(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 53 ms 352 KB Output is correct
4 Correct 58 ms 364 KB Output is correct
5 Correct 56 ms 336 KB Output is correct
6 Correct 56 ms 360 KB Output is correct
7 Correct 60 ms 336 KB Output is correct
8 Correct 57 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 53 ms 352 KB Output is correct
4 Correct 58 ms 364 KB Output is correct
5 Correct 56 ms 336 KB Output is correct
6 Correct 56 ms 360 KB Output is correct
7 Correct 60 ms 336 KB Output is correct
8 Correct 57 ms 336 KB Output is correct
9 Correct 1 ms 260 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 56 ms 336 KB Output is correct
30 Correct 57 ms 356 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 14 ms 336 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
37 Correct 57 ms 664 KB Output is correct
38 Correct 60 ms 592 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 2 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 2 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 688 ms 4560 KB Output is correct
2 Correct 1045 ms 8776 KB Output is correct
3 Correct 967 ms 8760 KB Output is correct
4 Correct 1036 ms 8784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 688 ms 4560 KB Output is correct
2 Correct 1045 ms 8776 KB Output is correct
3 Correct 967 ms 8760 KB Output is correct
4 Correct 1036 ms 8784 KB Output is correct
5 Execution timed out 3091 ms 4560 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 688 ms 4560 KB Output is correct
14 Correct 1045 ms 8776 KB Output is correct
15 Correct 967 ms 8760 KB Output is correct
16 Correct 1036 ms 8784 KB Output is correct
17 Execution timed out 3091 ms 4560 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 53 ms 352 KB Output is correct
4 Correct 58 ms 364 KB Output is correct
5 Correct 56 ms 336 KB Output is correct
6 Correct 56 ms 360 KB Output is correct
7 Correct 60 ms 336 KB Output is correct
8 Correct 57 ms 336 KB Output is correct
9 Correct 1 ms 260 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 56 ms 336 KB Output is correct
30 Correct 57 ms 356 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 14 ms 336 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
37 Correct 57 ms 664 KB Output is correct
38 Correct 60 ms 592 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 2 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 2 ms 336 KB Output is correct
43 Execution timed out 3057 ms 592 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 53 ms 352 KB Output is correct
4 Correct 58 ms 364 KB Output is correct
5 Correct 56 ms 336 KB Output is correct
6 Correct 56 ms 360 KB Output is correct
7 Correct 60 ms 336 KB Output is correct
8 Correct 57 ms 336 KB Output is correct
9 Correct 1 ms 260 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 56 ms 336 KB Output is correct
30 Correct 57 ms 356 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 2 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 14 ms 336 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
37 Correct 57 ms 664 KB Output is correct
38 Correct 60 ms 592 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 2 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 2 ms 336 KB Output is correct
43 Correct 688 ms 4560 KB Output is correct
44 Correct 1045 ms 8776 KB Output is correct
45 Correct 967 ms 8760 KB Output is correct
46 Correct 1036 ms 8784 KB Output is correct
47 Execution timed out 3091 ms 4560 KB Time limit exceeded
48 Halted 0 ms 0 KB -