Submission #633069

# Submission time Handle Problem Language Result Execution time Memory
633069 2022-08-21T14:20:14 Z tutis Digital Circuit (IOI22_circuit) C++17
46 / 100
3000 ms 5064 KB
#include "circuit.h"
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000002022;
vector<pair<ll, ll>>a;

vector<int>P;
vector<int>A;
vector<vector<int>>c;
int N, M;
vector<bool> F(200009, false);
vector<int> L, R;
void calc(int i)
{
    int d = c[i].size();
    vector<ll> k(d + 2, 0ll);
    ll v = 1;
    a[i] = {0ll, 0ll};
    for (int j : c[i])
    {
        int v0 = a[j].first;
        int v1 = a[j].second;
        if (F[j])
            swap(v0, v1);
        ll a1_ = 0;
        ll a0_ = 0;
        a1_ = a[i].second * (v0 + v1) + v * v1;
        a0_ = a[i].first * (v0 + v1) + v * v0;
        a[i].first = a0_;
        a[i].second = a1_;
        v *= (v0 + v1);
        a[i].first %= mod;
        a[i].second %= mod;
        v %= mod;
    }
}
vector<ll>D;
void init(int N_, int M_, vector<int> P_, vector<int> A_) {
    P = P_;
    A = A_;
    N = N_;
    M = M_;
    c = vector<vector<int>>(N + M);
    for (int i = 1; i < N + M; i++)
        c[P[i]].push_back(i);
    ll prod[N + M];
    {
        function<void(int)>dfs = [&](int i)->void
        {
            prod[i] = max(1, (int)c[i].size());
            for (int j : c[i])
            {
                dfs(j);
                prod[i] *= prod[j];
                prod[i] %= mod;
            }
        };
        dfs(0);
    }
    D = vector<ll>(N + M);
    {
        function<void(int, ll)>dfs = [&](int i, ll ss)->void
        {
            D[i] = ss;
            vector<ll>s;
            int cnt = 0;
            for (int j : c[i])
            {
                s.push_back(prod[j]);
                cnt++;
            }
            vector<ll>t = s;
            reverse(t.begin(), t.end());
            s.insert(s.begin(), 1);
            t.insert(t.begin(), 1);
            for (int i = 1; i < (int)s.size(); i++)
                s[i] = (s[i - 1] * s[i]) % mod;
            for (int i = 1; i < (int)t.size(); i++)
                t[i] = (t[i - 1] * t[i]) % mod;
            int k = 0;
            for (int j : c[i])
            {
                ll s_ = ss;
                s_ *= s[k];
                s_ %= mod;
                s_ *= t[cnt - 1 - k];
                s_ %= mod;
                dfs(j, s_);
                k++;
            }
        };
        dfs(0, 1);
    }
}
int count_ways(int X, int Y) {
    X -= N;
    Y -= N;
    for (int i = X; i <= Y; i++)
        A[i] ^= 1;
    ll ret = 0;
    for (int i = 0; i < M; i++)
        if (A[i] == 1)
        {
            ret += D[i + N];
            ret %= mod;
        }
    return (int)ret;
}
# 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 336 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 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 1 ms 720 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 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 208 KB Output is correct
10 Correct 1 ms 336 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 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 720 KB Output is correct
19 Correct 1 ms 720 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 464 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 720 KB Output is correct
37 Correct 1 ms 720 KB Output is correct
38 Correct 1 ms 720 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 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 3092 ms 5064 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3092 ms 5064 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 336 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 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 1 ms 720 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Execution timed out 3092 ms 5064 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 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 208 KB Output is correct
10 Correct 1 ms 336 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 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 720 KB Output is correct
19 Correct 1 ms 720 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 464 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 720 KB Output is correct
37 Correct 1 ms 720 KB Output is correct
38 Correct 1 ms 720 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1319 ms 720 KB Output is correct
44 Correct 1554 ms 720 KB Output is correct
45 Correct 1741 ms 720 KB Output is correct
46 Correct 2213 ms 1064 KB Output is correct
47 Correct 2518 ms 976 KB Output is correct
48 Correct 2360 ms 1084 KB Output is correct
49 Correct 2496 ms 1012 KB Output is correct
50 Correct 2129 ms 976 KB Output is correct
51 Correct 2595 ms 772 KB Output is correct
52 Correct 2291 ms 772 KB Output is correct
53 Correct 961 ms 1872 KB Output is correct
54 Correct 2396 ms 956 KB Output is correct
55 Correct 2303 ms 848 KB Output is correct
56 Correct 2392 ms 720 KB Output is correct
57 Correct 2154 ms 592 KB Output is correct
58 Correct 2369 ms 2284 KB Output is correct
59 Correct 2646 ms 2384 KB Output is correct
60 Correct 2405 ms 2296 KB Output is correct
61 Correct 1501 ms 1104 KB Output is correct
62 Correct 1787 ms 720 KB Output is correct
63 Correct 2005 ms 592 KB Output is correct
64 Correct 2449 ms 592 KB Output is correct
65 Correct 776 ms 592 KB Output is correct
66 Correct 2190 ms 848 KB Output is correct
67 Correct 2120 ms 848 KB Output is correct
68 Correct 2140 ms 924 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 208 KB Output is correct
10 Correct 1 ms 336 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 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 720 KB Output is correct
19 Correct 1 ms 720 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 464 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 720 KB Output is correct
37 Correct 1 ms 720 KB Output is correct
38 Correct 1 ms 720 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 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 3092 ms 5064 KB Time limit exceeded
44 Halted 0 ms 0 KB -