답안 #948146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948146 2024-03-17T16:40:04 Z Nhoksocqt1 디지털 회로 (IOI22_circuit) C++17
18 / 100
18 ms 22464 KB
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
	inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
	inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int MAXN = 200005;
const int MOD = 1000002022;

vector<int> adj[MAXN];
int f[2003][2], g[2003][2003];
int pa[MAXN], sz[MAXN], nArr, mArr;
bool state[MAXN];

void init(int _N, int _M, vector<int> _P, vector<int> _A) {
    nArr = _N, mArr = _M;
    for (int i = 0; i < nArr + mArr; ++i) {
        pa[i] = _P[i];
        if(pa[i] != -1)
            adj[pa[i]].push_back(i);
    }

    for (int i = 0; i < mArr; ++i)
        state[nArr + i] = _A[i];
}

int count_ways(int L, int R) {
    for (int i = L; i <= R; ++i)
        state[i] = 1 - state[i];

    for (int i = nArr + mArr - 1; i >= 0; --i) {
        for (int j = 0; j <= sz[i]; ++j)
            g[i][j] = 0;

        f[i][0] = f[i][1] = 0;
    }

    for (int i = nArr + mArr - 1; i >= 0; --i) {
        if(i >= nArr) {
            f[i][state[i]] = 1;
            sz[i] = 1;
        } else {
            sz[i] = 0;
            g[i][0] = 1;
            for (int it = 0; it < sz(adj[i]); ++it) {
                int j(adj[i][it]);

                ++sz[i];
                for (int k = sz[i]; k >= 0; --k)
                    g[i][k] = (1LL * g[i][k] * f[j][0] + 1LL * (k > 0 ? g[i][k - 1] : 0) * f[j][1]) % MOD;
            }

            for (int j = 0; j <= sz[i]; ++j) {
                f[i][0] = (f[i][0] + 1LL * g[i][j] * (sz[i] - j)) % MOD;
                f[i][1] = (f[i][1] + 1LL * g[i][j] * j) % MOD;
            }
        }
    }

    return f[0][1];
}

#ifdef Nhoksocqt1

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    #define TASK "circuit"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    vector<int> _P, _A;
    int _N, _M, _Q;
    cin >> _N >> _M >> _Q;

    _P.resize(_N + _M);

    for (int i = 0; i < _N + _M; ++i)
        cin >> _P[i];

    _A.resize(_M);
    for (int i = 0; i < _M; ++i)
        cin >> _A[i];

    init(_N, _M, _P, _A);
    for (int t = 0; t < _Q; ++t) {
        int _L, _R;
        cin >> _L >> _R;
        cout << count_ways(_L, _R) << '\n';
    }

    return 0;
}

#endif // Nhoksocqt1
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 8024 KB Output is correct
3 Correct 7 ms 16216 KB Output is correct
4 Correct 7 ms 16216 KB Output is correct
5 Correct 7 ms 16216 KB Output is correct
6 Correct 7 ms 16292 KB Output is correct
7 Correct 7 ms 16216 KB Output is correct
8 Correct 7 ms 16216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 12120 KB Output is correct
3 Correct 3 ms 16216 KB Output is correct
4 Correct 3 ms 16216 KB Output is correct
5 Correct 4 ms 16216 KB Output is correct
6 Correct 5 ms 20320 KB Output is correct
7 Correct 4 ms 22360 KB Output is correct
8 Correct 4 ms 22360 KB Output is correct
9 Correct 4 ms 22360 KB Output is correct
10 Correct 4 ms 22360 KB Output is correct
11 Correct 4 ms 22360 KB Output is correct
12 Correct 4 ms 22360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 8024 KB Output is correct
3 Correct 7 ms 16216 KB Output is correct
4 Correct 7 ms 16216 KB Output is correct
5 Correct 7 ms 16216 KB Output is correct
6 Correct 7 ms 16292 KB Output is correct
7 Correct 7 ms 16216 KB Output is correct
8 Correct 7 ms 16216 KB Output is correct
9 Correct 2 ms 8024 KB Output is correct
10 Correct 2 ms 12120 KB Output is correct
11 Correct 3 ms 16216 KB Output is correct
12 Correct 3 ms 16216 KB Output is correct
13 Correct 4 ms 16216 KB Output is correct
14 Correct 5 ms 20320 KB Output is correct
15 Correct 4 ms 22360 KB Output is correct
16 Correct 4 ms 22360 KB Output is correct
17 Correct 4 ms 22360 KB Output is correct
18 Correct 4 ms 22360 KB Output is correct
19 Correct 4 ms 22360 KB Output is correct
20 Correct 4 ms 22360 KB Output is correct
21 Correct 4 ms 22360 KB Output is correct
22 Correct 3 ms 18264 KB Output is correct
23 Correct 4 ms 18264 KB Output is correct
24 Correct 4 ms 22360 KB Output is correct
25 Correct 4 ms 22360 KB Output is correct
26 Correct 4 ms 22360 KB Output is correct
27 Correct 4 ms 22464 KB Output is correct
28 Correct 4 ms 22360 KB Output is correct
29 Correct 8 ms 16060 KB Output is correct
30 Correct 7 ms 16216 KB Output is correct
31 Correct 3 ms 16216 KB Output is correct
32 Correct 4 ms 22360 KB Output is correct
33 Correct 4 ms 20312 KB Output is correct
34 Correct 4 ms 18264 KB Output is correct
35 Correct 4 ms 16216 KB Output is correct
36 Correct 5 ms 22360 KB Output is correct
37 Correct 8 ms 22360 KB Output is correct
38 Correct 8 ms 22336 KB Output is correct
39 Correct 3 ms 18264 KB Output is correct
40 Correct 3 ms 18208 KB Output is correct
41 Correct 4 ms 18516 KB Output is correct
42 Correct 3 ms 16216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 18840 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 18840 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 12120 KB Output is correct
3 Correct 3 ms 16216 KB Output is correct
4 Correct 3 ms 16216 KB Output is correct
5 Correct 4 ms 16216 KB Output is correct
6 Correct 5 ms 20320 KB Output is correct
7 Correct 4 ms 22360 KB Output is correct
8 Correct 4 ms 22360 KB Output is correct
9 Correct 4 ms 22360 KB Output is correct
10 Correct 4 ms 22360 KB Output is correct
11 Correct 4 ms 22360 KB Output is correct
12 Correct 4 ms 22360 KB Output is correct
13 Runtime error 18 ms 18840 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 8024 KB Output is correct
3 Correct 7 ms 16216 KB Output is correct
4 Correct 7 ms 16216 KB Output is correct
5 Correct 7 ms 16216 KB Output is correct
6 Correct 7 ms 16292 KB Output is correct
7 Correct 7 ms 16216 KB Output is correct
8 Correct 7 ms 16216 KB Output is correct
9 Correct 2 ms 8024 KB Output is correct
10 Correct 2 ms 12120 KB Output is correct
11 Correct 3 ms 16216 KB Output is correct
12 Correct 3 ms 16216 KB Output is correct
13 Correct 4 ms 16216 KB Output is correct
14 Correct 5 ms 20320 KB Output is correct
15 Correct 4 ms 22360 KB Output is correct
16 Correct 4 ms 22360 KB Output is correct
17 Correct 4 ms 22360 KB Output is correct
18 Correct 4 ms 22360 KB Output is correct
19 Correct 4 ms 22360 KB Output is correct
20 Correct 4 ms 22360 KB Output is correct
21 Correct 4 ms 22360 KB Output is correct
22 Correct 3 ms 18264 KB Output is correct
23 Correct 4 ms 18264 KB Output is correct
24 Correct 4 ms 22360 KB Output is correct
25 Correct 4 ms 22360 KB Output is correct
26 Correct 4 ms 22360 KB Output is correct
27 Correct 4 ms 22464 KB Output is correct
28 Correct 4 ms 22360 KB Output is correct
29 Correct 8 ms 16060 KB Output is correct
30 Correct 7 ms 16216 KB Output is correct
31 Correct 3 ms 16216 KB Output is correct
32 Correct 4 ms 22360 KB Output is correct
33 Correct 4 ms 20312 KB Output is correct
34 Correct 4 ms 18264 KB Output is correct
35 Correct 4 ms 16216 KB Output is correct
36 Correct 5 ms 22360 KB Output is correct
37 Correct 8 ms 22360 KB Output is correct
38 Correct 8 ms 22336 KB Output is correct
39 Correct 3 ms 18264 KB Output is correct
40 Correct 3 ms 18208 KB Output is correct
41 Correct 4 ms 18516 KB Output is correct
42 Correct 3 ms 16216 KB Output is correct
43 Runtime error 8 ms 16216 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 8024 KB Output is correct
3 Correct 7 ms 16216 KB Output is correct
4 Correct 7 ms 16216 KB Output is correct
5 Correct 7 ms 16216 KB Output is correct
6 Correct 7 ms 16292 KB Output is correct
7 Correct 7 ms 16216 KB Output is correct
8 Correct 7 ms 16216 KB Output is correct
9 Correct 2 ms 8024 KB Output is correct
10 Correct 2 ms 12120 KB Output is correct
11 Correct 3 ms 16216 KB Output is correct
12 Correct 3 ms 16216 KB Output is correct
13 Correct 4 ms 16216 KB Output is correct
14 Correct 5 ms 20320 KB Output is correct
15 Correct 4 ms 22360 KB Output is correct
16 Correct 4 ms 22360 KB Output is correct
17 Correct 4 ms 22360 KB Output is correct
18 Correct 4 ms 22360 KB Output is correct
19 Correct 4 ms 22360 KB Output is correct
20 Correct 4 ms 22360 KB Output is correct
21 Correct 4 ms 22360 KB Output is correct
22 Correct 3 ms 18264 KB Output is correct
23 Correct 4 ms 18264 KB Output is correct
24 Correct 4 ms 22360 KB Output is correct
25 Correct 4 ms 22360 KB Output is correct
26 Correct 4 ms 22360 KB Output is correct
27 Correct 4 ms 22464 KB Output is correct
28 Correct 4 ms 22360 KB Output is correct
29 Correct 8 ms 16060 KB Output is correct
30 Correct 7 ms 16216 KB Output is correct
31 Correct 3 ms 16216 KB Output is correct
32 Correct 4 ms 22360 KB Output is correct
33 Correct 4 ms 20312 KB Output is correct
34 Correct 4 ms 18264 KB Output is correct
35 Correct 4 ms 16216 KB Output is correct
36 Correct 5 ms 22360 KB Output is correct
37 Correct 8 ms 22360 KB Output is correct
38 Correct 8 ms 22336 KB Output is correct
39 Correct 3 ms 18264 KB Output is correct
40 Correct 3 ms 18208 KB Output is correct
41 Correct 4 ms 18516 KB Output is correct
42 Correct 3 ms 16216 KB Output is correct
43 Runtime error 18 ms 18840 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -