답안 #711269

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711269 2023-03-16T12:15:35 Z Jarif_Rahman 디지털 회로 (IOI22_circuit) C++17
18 / 100
3000 ms 8588 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

const ll md = 1000002022;

int n, m;
vector<int> P, A;
vector<vector<int>> tree;
vector<ll> dp, total;

void dfs(int nd){
    for(int x: tree[nd]) dfs(x);

    if(nd >= n){
        dp[nd] = A[nd-n];
        return;
    }
    total[nd] = tree[nd].size();
    for(ll x: tree[nd]) total[nd]*=total[x], total[nd]%=md;

    int k = tree[nd].size();
    vector<ll> a, b;
    for(int x: tree[nd]) a.pb(dp[x]), b.pb((total[x]-dp[x])%md);

    vector<vector<ll>> dp2(k, vector<ll>(k+1, 0));
    dp2[0][0] = b[0];
    dp2[0][1] = a[0];
    for(int i = 1; i < k; i++) for(int j = 0; j <= i+1; j++){
        dp2[i][j] = (dp2[i-1][j]*b[i])%md;
        if(j) dp2[i][j]+=(dp2[i-1][j-1]*a[i])%md, dp2[i][j]%=md;
    }

    dp[nd] = 0;
    for(int i = 1; i <= k; i++) dp[nd]+=(dp2[k-1][i]*i)%md, dp[nd]%=md;
}

void init(int _n, int _m, vector<int> _P, vector<int> _A){
    swap(n, _n), swap(m, _m), swap(P, _P), swap(A, _A);
    tree.resize(n+m);
    for(int i = 1; i < n+m; i++) tree[P[i]].pb(i);
}

int count_ways(int L, int R){
    for(int i = L; i <= R; i++) A[i-n] = !A[i-n];
    dp.assign(n+m, 0);
    total.assign(n+m, 1);
    dfs(0);

    if(dp[0] < 0) dp[0]+=md;
    return dp[0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 28 ms 7820 KB Output is correct
4 Correct 24 ms 8256 KB Output is correct
5 Correct 28 ms 8300 KB Output is correct
6 Correct 29 ms 8284 KB Output is correct
7 Correct 27 ms 8296 KB Output is correct
8 Correct 25 ms 8256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 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 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 28 ms 7820 KB Output is correct
4 Correct 24 ms 8256 KB Output is correct
5 Correct 28 ms 8300 KB Output is correct
6 Correct 29 ms 8284 KB Output is correct
7 Correct 27 ms 8296 KB Output is correct
8 Correct 25 ms 8256 KB Output is correct
9 Correct 1 ms 208 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 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 2 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 27 ms 8256 KB Output is correct
30 Correct 26 ms 8316 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 3 ms 336 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 8 ms 748 KB Output is correct
36 Correct 3 ms 592 KB Output is correct
37 Correct 28 ms 8580 KB Output is correct
38 Correct 28 ms 8588 KB Output is correct
39 Correct 2 ms 336 KB Output is correct
40 Correct 2 ms 336 KB Output is correct
41 Correct 2 ms 336 KB Output is correct
42 Correct 2 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3080 ms 4644 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3080 ms 4644 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 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 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Execution timed out 3080 ms 4644 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 28 ms 7820 KB Output is correct
4 Correct 24 ms 8256 KB Output is correct
5 Correct 28 ms 8300 KB Output is correct
6 Correct 29 ms 8284 KB Output is correct
7 Correct 27 ms 8296 KB Output is correct
8 Correct 25 ms 8256 KB Output is correct
9 Correct 1 ms 208 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 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 2 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 27 ms 8256 KB Output is correct
30 Correct 26 ms 8316 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 3 ms 336 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 8 ms 748 KB Output is correct
36 Correct 3 ms 592 KB Output is correct
37 Correct 28 ms 8580 KB Output is correct
38 Correct 28 ms 8588 KB Output is correct
39 Correct 2 ms 336 KB Output is correct
40 Correct 2 ms 336 KB Output is correct
41 Correct 2 ms 336 KB Output is correct
42 Correct 2 ms 336 KB Output is correct
43 Execution timed out 3016 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 0 ms 208 KB Output is correct
3 Correct 28 ms 7820 KB Output is correct
4 Correct 24 ms 8256 KB Output is correct
5 Correct 28 ms 8300 KB Output is correct
6 Correct 29 ms 8284 KB Output is correct
7 Correct 27 ms 8296 KB Output is correct
8 Correct 25 ms 8256 KB Output is correct
9 Correct 1 ms 208 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 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 2 ms 336 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 2 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 27 ms 8256 KB Output is correct
30 Correct 26 ms 8316 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 3 ms 336 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 8 ms 748 KB Output is correct
36 Correct 3 ms 592 KB Output is correct
37 Correct 28 ms 8580 KB Output is correct
38 Correct 28 ms 8588 KB Output is correct
39 Correct 2 ms 336 KB Output is correct
40 Correct 2 ms 336 KB Output is correct
41 Correct 2 ms 336 KB Output is correct
42 Correct 2 ms 336 KB Output is correct
43 Execution timed out 3080 ms 4644 KB Time limit exceeded
44 Halted 0 ms 0 KB -