답안 #1058086

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058086 2024-08-14T08:20:14 Z dozer 디지털 회로 (IOI22_circuit) C++17
18 / 100
3000 ms 31952 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n"
#define pii pair<int, int>
#define st first
#define nd second
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define LL node * 2
#define RR node * 2 + 1
#define ll long long
#define MAXN 500005

const int modulo = 1000002022;
const ll INF = 2e18 + 7;

int add(ll a, ll b){
    if (a + b < modulo) return a + b;
    return a + b - modulo;
}

int subs(ll a, ll b){
    if (a < b) return a - b + modulo;
    return a - b;
}

int mul(ll a, ll b){
    return (a * b) % modulo;
}

int fe(ll a, ll b){
    if (b == 0) return 1;
    if (b % 2) return mul(a, fe(a, b - 1));
    int tmp = fe(a, b / 2);
    return mul(tmp, tmp);
}

vector<int> adj[MAXN];
vector<int> dp[MAXN];
int one[MAXN], zero[MAXN], arr[MAXN];
int n, m;

void dfs(int node){
    if (adj[node].empty()){
        if (arr[node - n]) one[node] = 1;
        else one[node] = 0;
        zero[node] = 1 - one[node];
        return;
    }

    int k = adj[node].size();
    dp[node].resize(k + 1, 0);
    fill(dp[node].begin(), dp[node].end(), 0);
    dp[node][0] = 1;

    for (auto i : adj[node]){
        dfs(i);
        for (int j = k; j >= 1; j--){
            dp[node][j] = add(mul(dp[node][j], zero[i]), mul(dp[node][j - 1], one[i]));
        }
        dp[node][0] = mul(dp[node][0], zero[i]);
    }

    zero[node] = 0, one[node] = 0;
    for (int i = 0; i <= k; i++){
        zero[node] = add(zero[node], mul(dp[node][i], k - i));
        one[node] = add(one[node], mul(dp[node][i], i));
    }
    
}


void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n = N, m = M;
    for (int i = 1; i < n + m; i++)
        adj[P[i]].pb(i);

    for (int i = 0; i < m; i++) arr[i] = A[i];
    
}

int count_ways(int L, int R) {
    for (int i = L - n; i <= R - n; i++)
        arr[i] ^= 1;
    dfs(0);
    return one[0];
}
/*

int main() {
    fileio();
    int N, M, Q;
    assert(3 == scanf("%d %d %d", &N, &M, &Q));
    std::vector<int> P(N + M), A(M);
    for (int i = 0; i < N + M; ++i) {
    assert(1 == scanf("%d", &P[i]));
    }
    for (int j = 0; j < M; ++j) {
    assert(1 == scanf("%d", &A[j]));
    }
    init(N, M, P, A);

    for (int i = 0; i < Q; ++i) {
    int L, R;
    assert(2 == scanf("%d %d", &L, &R));
    printf("%d\n", count_ways(L, R));
    }
    return 0;
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 29528 KB Output is correct
2 Correct 3 ms 29528 KB Output is correct
3 Correct 18 ms 29528 KB Output is correct
4 Correct 19 ms 29528 KB Output is correct
5 Correct 19 ms 29528 KB Output is correct
6 Correct 18 ms 29528 KB Output is correct
7 Correct 19 ms 29528 KB Output is correct
8 Correct 19 ms 29528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 29528 KB Output is correct
2 Correct 3 ms 29636 KB Output is correct
3 Correct 4 ms 29528 KB Output is correct
4 Correct 4 ms 29528 KB Output is correct
5 Correct 4 ms 29528 KB Output is correct
6 Correct 4 ms 29528 KB Output is correct
7 Correct 5 ms 29528 KB Output is correct
8 Correct 4 ms 29528 KB Output is correct
9 Correct 5 ms 29528 KB Output is correct
10 Correct 4 ms 29784 KB Output is correct
11 Correct 4 ms 29784 KB Output is correct
12 Correct 4 ms 29624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 29528 KB Output is correct
2 Correct 3 ms 29528 KB Output is correct
3 Correct 18 ms 29528 KB Output is correct
4 Correct 19 ms 29528 KB Output is correct
5 Correct 19 ms 29528 KB Output is correct
6 Correct 18 ms 29528 KB Output is correct
7 Correct 19 ms 29528 KB Output is correct
8 Correct 19 ms 29528 KB Output is correct
9 Correct 4 ms 29528 KB Output is correct
10 Correct 3 ms 29636 KB Output is correct
11 Correct 4 ms 29528 KB Output is correct
12 Correct 4 ms 29528 KB Output is correct
13 Correct 4 ms 29528 KB Output is correct
14 Correct 4 ms 29528 KB Output is correct
15 Correct 5 ms 29528 KB Output is correct
16 Correct 4 ms 29528 KB Output is correct
17 Correct 5 ms 29528 KB Output is correct
18 Correct 4 ms 29784 KB Output is correct
19 Correct 4 ms 29784 KB Output is correct
20 Correct 4 ms 29624 KB Output is correct
21 Correct 4 ms 29528 KB Output is correct
22 Correct 4 ms 29600 KB Output is correct
23 Correct 4 ms 29528 KB Output is correct
24 Correct 4 ms 29528 KB Output is correct
25 Correct 4 ms 29528 KB Output is correct
26 Correct 4 ms 29528 KB Output is correct
27 Correct 4 ms 29528 KB Output is correct
28 Correct 4 ms 29528 KB Output is correct
29 Correct 18 ms 29648 KB Output is correct
30 Correct 19 ms 29528 KB Output is correct
31 Correct 4 ms 29784 KB Output is correct
32 Correct 4 ms 29528 KB Output is correct
33 Correct 4 ms 29528 KB Output is correct
34 Correct 4 ms 29528 KB Output is correct
35 Correct 9 ms 29528 KB Output is correct
36 Correct 4 ms 29784 KB Output is correct
37 Correct 18 ms 29784 KB Output is correct
38 Correct 19 ms 29820 KB Output is correct
39 Correct 4 ms 29528 KB Output is correct
40 Correct 4 ms 29528 KB Output is correct
41 Correct 4 ms 29528 KB Output is correct
42 Correct 4 ms 29528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3013 ms 31952 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3013 ms 31952 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 29528 KB Output is correct
2 Correct 3 ms 29636 KB Output is correct
3 Correct 4 ms 29528 KB Output is correct
4 Correct 4 ms 29528 KB Output is correct
5 Correct 4 ms 29528 KB Output is correct
6 Correct 4 ms 29528 KB Output is correct
7 Correct 5 ms 29528 KB Output is correct
8 Correct 4 ms 29528 KB Output is correct
9 Correct 5 ms 29528 KB Output is correct
10 Correct 4 ms 29784 KB Output is correct
11 Correct 4 ms 29784 KB Output is correct
12 Correct 4 ms 29624 KB Output is correct
13 Execution timed out 3013 ms 31952 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 29528 KB Output is correct
2 Correct 3 ms 29528 KB Output is correct
3 Correct 18 ms 29528 KB Output is correct
4 Correct 19 ms 29528 KB Output is correct
5 Correct 19 ms 29528 KB Output is correct
6 Correct 18 ms 29528 KB Output is correct
7 Correct 19 ms 29528 KB Output is correct
8 Correct 19 ms 29528 KB Output is correct
9 Correct 4 ms 29528 KB Output is correct
10 Correct 3 ms 29636 KB Output is correct
11 Correct 4 ms 29528 KB Output is correct
12 Correct 4 ms 29528 KB Output is correct
13 Correct 4 ms 29528 KB Output is correct
14 Correct 4 ms 29528 KB Output is correct
15 Correct 5 ms 29528 KB Output is correct
16 Correct 4 ms 29528 KB Output is correct
17 Correct 5 ms 29528 KB Output is correct
18 Correct 4 ms 29784 KB Output is correct
19 Correct 4 ms 29784 KB Output is correct
20 Correct 4 ms 29624 KB Output is correct
21 Correct 4 ms 29528 KB Output is correct
22 Correct 4 ms 29600 KB Output is correct
23 Correct 4 ms 29528 KB Output is correct
24 Correct 4 ms 29528 KB Output is correct
25 Correct 4 ms 29528 KB Output is correct
26 Correct 4 ms 29528 KB Output is correct
27 Correct 4 ms 29528 KB Output is correct
28 Correct 4 ms 29528 KB Output is correct
29 Correct 18 ms 29648 KB Output is correct
30 Correct 19 ms 29528 KB Output is correct
31 Correct 4 ms 29784 KB Output is correct
32 Correct 4 ms 29528 KB Output is correct
33 Correct 4 ms 29528 KB Output is correct
34 Correct 4 ms 29528 KB Output is correct
35 Correct 9 ms 29528 KB Output is correct
36 Correct 4 ms 29784 KB Output is correct
37 Correct 18 ms 29784 KB Output is correct
38 Correct 19 ms 29820 KB Output is correct
39 Correct 4 ms 29528 KB Output is correct
40 Correct 4 ms 29528 KB Output is correct
41 Correct 4 ms 29528 KB Output is correct
42 Correct 4 ms 29528 KB Output is correct
43 Execution timed out 3078 ms 29784 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 29528 KB Output is correct
2 Correct 3 ms 29528 KB Output is correct
3 Correct 18 ms 29528 KB Output is correct
4 Correct 19 ms 29528 KB Output is correct
5 Correct 19 ms 29528 KB Output is correct
6 Correct 18 ms 29528 KB Output is correct
7 Correct 19 ms 29528 KB Output is correct
8 Correct 19 ms 29528 KB Output is correct
9 Correct 4 ms 29528 KB Output is correct
10 Correct 3 ms 29636 KB Output is correct
11 Correct 4 ms 29528 KB Output is correct
12 Correct 4 ms 29528 KB Output is correct
13 Correct 4 ms 29528 KB Output is correct
14 Correct 4 ms 29528 KB Output is correct
15 Correct 5 ms 29528 KB Output is correct
16 Correct 4 ms 29528 KB Output is correct
17 Correct 5 ms 29528 KB Output is correct
18 Correct 4 ms 29784 KB Output is correct
19 Correct 4 ms 29784 KB Output is correct
20 Correct 4 ms 29624 KB Output is correct
21 Correct 4 ms 29528 KB Output is correct
22 Correct 4 ms 29600 KB Output is correct
23 Correct 4 ms 29528 KB Output is correct
24 Correct 4 ms 29528 KB Output is correct
25 Correct 4 ms 29528 KB Output is correct
26 Correct 4 ms 29528 KB Output is correct
27 Correct 4 ms 29528 KB Output is correct
28 Correct 4 ms 29528 KB Output is correct
29 Correct 18 ms 29648 KB Output is correct
30 Correct 19 ms 29528 KB Output is correct
31 Correct 4 ms 29784 KB Output is correct
32 Correct 4 ms 29528 KB Output is correct
33 Correct 4 ms 29528 KB Output is correct
34 Correct 4 ms 29528 KB Output is correct
35 Correct 9 ms 29528 KB Output is correct
36 Correct 4 ms 29784 KB Output is correct
37 Correct 18 ms 29784 KB Output is correct
38 Correct 19 ms 29820 KB Output is correct
39 Correct 4 ms 29528 KB Output is correct
40 Correct 4 ms 29528 KB Output is correct
41 Correct 4 ms 29528 KB Output is correct
42 Correct 4 ms 29528 KB Output is correct
43 Execution timed out 3013 ms 31952 KB Time limit exceeded
44 Halted 0 ms 0 KB -