답안 #633033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
633033 2022-08-21T12:18:26 Z tutis 디지털 회로 (IOI22_circuit) C++17
34 / 100
3000 ms 16052 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;
    }
}
void init(int N_, int M_, vector<int> P_, vector<int> A_) {
    P = P_;
    A = A_;
    N = N_;
    M = M_;
    a = vector<pair<ll, ll>>(N + M);
    c = vector<vector<int>>(N + M);
    L = vector<int>(N + M);
    R = vector<int>(N + M);
    for (int i = 1; i < N + M; i++)
        c[P[i]].push_back(i);
    for (int i = N + M - 1; i >= N; i--)
    {
        if (A[i - N] == 1)
            a[i] = {0, 1};
        else
            a[i] = {1, 0};
        L[i] = R[i] = i;
    }
    for (int i = N - 1; i >= 0; i--)
    {
        calc(i);
        L[i] = N + M + 5;
        R[i] = -1;
        for (int j : c[i])
        {
            L[i] = min(L[i], L[j]);
            R[i] = max(R[i], R[j]);
        }
    }
}

int count_ways(int X, int Y) {
    function<void(int)>f = [&](int i)->void
    {
        if (R[i] < X || Y < L[i])
            return;
        if (X <= L[i] && R[i] <= Y)
        {
            F[i] = F[i] ^ true;
        }
        else
        {
            for (int j : c[i])
            {
                F[j] = F[j] ^ F[i];
                f(j);
            }
            calc(i);
            F[i] = false;
        }
    };
    f(0);
    if (F[0])
        return a[0].first;
    return (int)a[0].second;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 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 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 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 0 ms 208 KB Output is correct
10 Correct 0 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 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 384 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 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 1 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 336 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 464 KB Output is correct
37 Correct 1 ms 464 KB Output is correct
38 Correct 1 ms 464 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
# 결과 실행 시간 메모리 Grader output
1 Correct 804 ms 5584 KB Output is correct
2 Correct 1150 ms 10748 KB Output is correct
3 Correct 1128 ms 10824 KB Output is correct
4 Correct 1044 ms 10832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 804 ms 5584 KB Output is correct
2 Correct 1150 ms 10748 KB Output is correct
3 Correct 1128 ms 10824 KB Output is correct
4 Correct 1044 ms 10832 KB Output is correct
5 Correct 982 ms 5564 KB Output is correct
6 Correct 1284 ms 10804 KB Output is correct
7 Correct 1198 ms 10824 KB Output is correct
8 Correct 1061 ms 10932 KB Output is correct
9 Correct 568 ms 592 KB Output is correct
10 Correct 1056 ms 976 KB Output is correct
11 Correct 929 ms 976 KB Output is correct
12 Correct 913 ms 976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 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 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 804 ms 5584 KB Output is correct
14 Correct 1150 ms 10748 KB Output is correct
15 Correct 1128 ms 10824 KB Output is correct
16 Correct 1044 ms 10832 KB Output is correct
17 Correct 982 ms 5564 KB Output is correct
18 Correct 1284 ms 10804 KB Output is correct
19 Correct 1198 ms 10824 KB Output is correct
20 Correct 1061 ms 10932 KB Output is correct
21 Correct 568 ms 592 KB Output is correct
22 Correct 1056 ms 976 KB Output is correct
23 Correct 929 ms 976 KB Output is correct
24 Correct 913 ms 976 KB Output is correct
25 Execution timed out 3097 ms 16052 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 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 0 ms 208 KB Output is correct
10 Correct 0 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 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 384 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 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 1 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 336 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 464 KB Output is correct
37 Correct 1 ms 464 KB Output is correct
38 Correct 1 ms 464 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 3059 ms 720 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 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 0 ms 208 KB Output is correct
10 Correct 0 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 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 384 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 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 1 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 336 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 464 KB Output is correct
37 Correct 1 ms 464 KB Output is correct
38 Correct 1 ms 464 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 804 ms 5584 KB Output is correct
44 Correct 1150 ms 10748 KB Output is correct
45 Correct 1128 ms 10824 KB Output is correct
46 Correct 1044 ms 10832 KB Output is correct
47 Correct 982 ms 5564 KB Output is correct
48 Correct 1284 ms 10804 KB Output is correct
49 Correct 1198 ms 10824 KB Output is correct
50 Correct 1061 ms 10932 KB Output is correct
51 Correct 568 ms 592 KB Output is correct
52 Correct 1056 ms 976 KB Output is correct
53 Correct 929 ms 976 KB Output is correct
54 Correct 913 ms 976 KB Output is correct
55 Execution timed out 3097 ms 16052 KB Time limit exceeded
56 Halted 0 ms 0 KB -