Submission #1024529

# Submission time Handle Problem Language Result Execution time Memory
1024529 2024-07-16T07:01:12 Z vjudge1 Digital Circuit (IOI22_circuit) C++17
18 / 100
17 ms 20568 KB
#include <bits/stdc++.h>
#define ent '\n'

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 12;
const int mod = 1e9 + 2022;

vector<int> g[maxn];
ll dp[2005][2005];
ll ways[2005][2];
int p[maxn];
int a[maxn];
int n, m;

void init(int N, int M, std::vector<int> P, std::vector<int> A){
    n = N, m = M;
    for(int i=0;i<n+m;i++){
        p[i] = P[i];
        if(i >= n) a[i] = A[i-n];
        if(i >= 1) g[p[i]].push_back(i);
    }
}

int count_ways(int L, int R){
    for(int i=L;i<=R;i++){
        a[i] ^= 1;
    }
    for(int i=n;i<n+m;i++){
        ways[i][a[i]] = 1;
        ways[i][1-a[i]] = 0;
    }
    for(int v=n-1;v>=0;v--){
        for(int i=0;i<=n+m;i++){
            dp[v][i] = 0;
        }
        dp[v][0] = 1;
        ways[v][0] = ways[v][1] = 0;
        for(int to:g[v]){
            for(int i=g[v].size();i>=0;i--){
                dp[v][i] = (dp[v][i] * ways[to][0]) % mod;
                if(i > 0) dp[v][i] = (dp[v][i] + dp[v][i-1] * ways[to][1]) % mod;
            }
        }
        for(int i=0;i<=(int)g[v].size();i++){
            ways[v][0] = (ways[v][0] + dp[v][i] * ((int)g[v].size() - i)) % mod;
            ways[v][1] = (ways[v][1] + dp[v][i] * i) % mod;
        }
    }
    return ways[0][1];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5976 KB Output is correct
2 Correct 1 ms 5976 KB Output is correct
3 Correct 12 ms 5976 KB Output is correct
4 Correct 12 ms 5976 KB Output is correct
5 Correct 13 ms 5976 KB Output is correct
6 Correct 13 ms 5976 KB Output is correct
7 Correct 13 ms 5976 KB Output is correct
8 Correct 13 ms 5976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5976 KB Output is correct
2 Correct 2 ms 10072 KB Output is correct
3 Correct 3 ms 14168 KB Output is correct
4 Correct 3 ms 14168 KB Output is correct
5 Correct 2 ms 14168 KB Output is correct
6 Correct 3 ms 16216 KB Output is correct
7 Correct 5 ms 20568 KB Output is correct
8 Correct 5 ms 20568 KB Output is correct
9 Correct 4 ms 20568 KB Output is correct
10 Correct 4 ms 20568 KB Output is correct
11 Correct 5 ms 20568 KB Output is correct
12 Correct 4 ms 18520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5976 KB Output is correct
2 Correct 1 ms 5976 KB Output is correct
3 Correct 12 ms 5976 KB Output is correct
4 Correct 12 ms 5976 KB Output is correct
5 Correct 13 ms 5976 KB Output is correct
6 Correct 13 ms 5976 KB Output is correct
7 Correct 13 ms 5976 KB Output is correct
8 Correct 13 ms 5976 KB Output is correct
9 Correct 1 ms 5976 KB Output is correct
10 Correct 2 ms 10072 KB Output is correct
11 Correct 3 ms 14168 KB Output is correct
12 Correct 3 ms 14168 KB Output is correct
13 Correct 2 ms 14168 KB Output is correct
14 Correct 3 ms 16216 KB Output is correct
15 Correct 5 ms 20568 KB Output is correct
16 Correct 5 ms 20568 KB Output is correct
17 Correct 4 ms 20568 KB Output is correct
18 Correct 4 ms 20568 KB Output is correct
19 Correct 5 ms 20568 KB Output is correct
20 Correct 4 ms 18520 KB Output is correct
21 Correct 4 ms 16216 KB Output is correct
22 Correct 4 ms 18264 KB Output is correct
23 Correct 3 ms 16216 KB Output is correct
24 Correct 5 ms 20568 KB Output is correct
25 Correct 5 ms 20568 KB Output is correct
26 Correct 5 ms 20568 KB Output is correct
27 Correct 5 ms 20568 KB Output is correct
28 Correct 5 ms 20568 KB Output is correct
29 Correct 12 ms 5976 KB Output is correct
30 Correct 14 ms 5976 KB Output is correct
31 Correct 4 ms 20312 KB Output is correct
32 Correct 5 ms 20568 KB Output is correct
33 Correct 3 ms 14168 KB Output is correct
34 Correct 2 ms 10144 KB Output is correct
35 Correct 4 ms 5976 KB Output is correct
36 Correct 5 ms 20568 KB Output is correct
37 Correct 16 ms 20568 KB Output is correct
38 Correct 17 ms 20568 KB Output is correct
39 Correct 3 ms 16216 KB Output is correct
40 Correct 3 ms 14168 KB Output is correct
41 Correct 3 ms 12120 KB Output is correct
42 Correct 2 ms 5976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 15056 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 15056 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5976 KB Output is correct
2 Correct 2 ms 10072 KB Output is correct
3 Correct 3 ms 14168 KB Output is correct
4 Correct 3 ms 14168 KB Output is correct
5 Correct 2 ms 14168 KB Output is correct
6 Correct 3 ms 16216 KB Output is correct
7 Correct 5 ms 20568 KB Output is correct
8 Correct 5 ms 20568 KB Output is correct
9 Correct 4 ms 20568 KB Output is correct
10 Correct 4 ms 20568 KB Output is correct
11 Correct 5 ms 20568 KB Output is correct
12 Correct 4 ms 18520 KB Output is correct
13 Runtime error 14 ms 15056 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5976 KB Output is correct
2 Correct 1 ms 5976 KB Output is correct
3 Correct 12 ms 5976 KB Output is correct
4 Correct 12 ms 5976 KB Output is correct
5 Correct 13 ms 5976 KB Output is correct
6 Correct 13 ms 5976 KB Output is correct
7 Correct 13 ms 5976 KB Output is correct
8 Correct 13 ms 5976 KB Output is correct
9 Correct 1 ms 5976 KB Output is correct
10 Correct 2 ms 10072 KB Output is correct
11 Correct 3 ms 14168 KB Output is correct
12 Correct 3 ms 14168 KB Output is correct
13 Correct 2 ms 14168 KB Output is correct
14 Correct 3 ms 16216 KB Output is correct
15 Correct 5 ms 20568 KB Output is correct
16 Correct 5 ms 20568 KB Output is correct
17 Correct 4 ms 20568 KB Output is correct
18 Correct 4 ms 20568 KB Output is correct
19 Correct 5 ms 20568 KB Output is correct
20 Correct 4 ms 18520 KB Output is correct
21 Correct 4 ms 16216 KB Output is correct
22 Correct 4 ms 18264 KB Output is correct
23 Correct 3 ms 16216 KB Output is correct
24 Correct 5 ms 20568 KB Output is correct
25 Correct 5 ms 20568 KB Output is correct
26 Correct 5 ms 20568 KB Output is correct
27 Correct 5 ms 20568 KB Output is correct
28 Correct 5 ms 20568 KB Output is correct
29 Correct 12 ms 5976 KB Output is correct
30 Correct 14 ms 5976 KB Output is correct
31 Correct 4 ms 20312 KB Output is correct
32 Correct 5 ms 20568 KB Output is correct
33 Correct 3 ms 14168 KB Output is correct
34 Correct 2 ms 10144 KB Output is correct
35 Correct 4 ms 5976 KB Output is correct
36 Correct 5 ms 20568 KB Output is correct
37 Correct 16 ms 20568 KB Output is correct
38 Correct 17 ms 20568 KB Output is correct
39 Correct 3 ms 16216 KB Output is correct
40 Correct 3 ms 14168 KB Output is correct
41 Correct 3 ms 12120 KB Output is correct
42 Correct 2 ms 5976 KB Output is correct
43 Runtime error 7 ms 12376 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5976 KB Output is correct
2 Correct 1 ms 5976 KB Output is correct
3 Correct 12 ms 5976 KB Output is correct
4 Correct 12 ms 5976 KB Output is correct
5 Correct 13 ms 5976 KB Output is correct
6 Correct 13 ms 5976 KB Output is correct
7 Correct 13 ms 5976 KB Output is correct
8 Correct 13 ms 5976 KB Output is correct
9 Correct 1 ms 5976 KB Output is correct
10 Correct 2 ms 10072 KB Output is correct
11 Correct 3 ms 14168 KB Output is correct
12 Correct 3 ms 14168 KB Output is correct
13 Correct 2 ms 14168 KB Output is correct
14 Correct 3 ms 16216 KB Output is correct
15 Correct 5 ms 20568 KB Output is correct
16 Correct 5 ms 20568 KB Output is correct
17 Correct 4 ms 20568 KB Output is correct
18 Correct 4 ms 20568 KB Output is correct
19 Correct 5 ms 20568 KB Output is correct
20 Correct 4 ms 18520 KB Output is correct
21 Correct 4 ms 16216 KB Output is correct
22 Correct 4 ms 18264 KB Output is correct
23 Correct 3 ms 16216 KB Output is correct
24 Correct 5 ms 20568 KB Output is correct
25 Correct 5 ms 20568 KB Output is correct
26 Correct 5 ms 20568 KB Output is correct
27 Correct 5 ms 20568 KB Output is correct
28 Correct 5 ms 20568 KB Output is correct
29 Correct 12 ms 5976 KB Output is correct
30 Correct 14 ms 5976 KB Output is correct
31 Correct 4 ms 20312 KB Output is correct
32 Correct 5 ms 20568 KB Output is correct
33 Correct 3 ms 14168 KB Output is correct
34 Correct 2 ms 10144 KB Output is correct
35 Correct 4 ms 5976 KB Output is correct
36 Correct 5 ms 20568 KB Output is correct
37 Correct 16 ms 20568 KB Output is correct
38 Correct 17 ms 20568 KB Output is correct
39 Correct 3 ms 16216 KB Output is correct
40 Correct 3 ms 14168 KB Output is correct
41 Correct 3 ms 12120 KB Output is correct
42 Correct 2 ms 5976 KB Output is correct
43 Runtime error 14 ms 15056 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -