Submission #780360

# Submission time Handle Problem Language Result Execution time Memory
780360 2023-07-12T08:29:35 Z mousebeaver Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 4152 KB
#define ll long long
#define pll pair<ll, ll>
#define MOD 1000002022
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

ll n = 0;
vector<ll> a(0);
vector<vector<ll>> adjlist(0);

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

pll dfs(int i) //On, off
{
    if(adjlist[i].empty())
    {
        return {a[i], 1-a[i]};
    }

    ll c = adjlist[i].size();
    ll all = c;
    vector<ll> dp(c+1, 0); //Possibilities for being on
    dp[0] = 1;

    for(ll j : adjlist[i])
    {
        pll p = dfs(j);
        all = (all * ((p.first+p.second)%MOD))%MOD;
        vector<ll> postdp(c+1, 0);
        for(ll k = 0; k <= c; k++)
        {
            postdp[k] = (dp[k]*p.second)%MOD;
            if(k > 0)
            {
                postdp[k] = (postdp[k] + (dp[k-1]*p.first)%MOD)%MOD;
            }
        }
        dp = postdp;
    }

    ll on = 0;
    for(ll k = c; k > 0; k--)
    {
        on = (on+((dp[k]*k)%MOD))%MOD;
    }

    return {on, (all+MOD-on)%MOD};
}

int count_ways(int L, int R) 
{
    for(ll i = L; i <= R; i++)
    {
        a[i] = 1-a[i];
    }
    return dfs(0).first;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 17 ms 384 KB Output is correct
4 Correct 18 ms 368 KB Output is correct
5 Correct 18 ms 336 KB Output is correct
6 Correct 18 ms 336 KB Output is correct
7 Correct 19 ms 360 KB Output is correct
8 Correct 18 ms 364 KB Output is correct
# Verdict Execution time Memory 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 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 1 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 17 ms 384 KB Output is correct
4 Correct 18 ms 368 KB Output is correct
5 Correct 18 ms 336 KB Output is correct
6 Correct 18 ms 336 KB Output is correct
7 Correct 19 ms 360 KB Output is correct
8 Correct 18 ms 364 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 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 1 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 2 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 18 ms 336 KB Output is correct
30 Correct 18 ms 360 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 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 4 ms 336 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 18 ms 592 KB Output is correct
38 Correct 18 ms 628 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 312 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3002 ms 4152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3002 ms 4152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 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 1 ms 592 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Execution timed out 3002 ms 4152 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 17 ms 384 KB Output is correct
4 Correct 18 ms 368 KB Output is correct
5 Correct 18 ms 336 KB Output is correct
6 Correct 18 ms 336 KB Output is correct
7 Correct 19 ms 360 KB Output is correct
8 Correct 18 ms 364 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 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 1 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 2 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 18 ms 336 KB Output is correct
30 Correct 18 ms 360 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 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 4 ms 336 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 18 ms 592 KB Output is correct
38 Correct 18 ms 628 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 312 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Execution timed out 3090 ms 548 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 17 ms 384 KB Output is correct
4 Correct 18 ms 368 KB Output is correct
5 Correct 18 ms 336 KB Output is correct
6 Correct 18 ms 336 KB Output is correct
7 Correct 19 ms 360 KB Output is correct
8 Correct 18 ms 364 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 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 1 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 2 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 18 ms 336 KB Output is correct
30 Correct 18 ms 360 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 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 4 ms 336 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 18 ms 592 KB Output is correct
38 Correct 18 ms 628 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 312 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Execution timed out 3002 ms 4152 KB Time limit exceeded
44 Halted 0 ms 0 KB -