Submission #786429

# Submission time Handle Problem Language Result Execution time Memory
786429 2023-07-18T07:44:56 Z vjudge1 Digital Circuit (IOI22_circuit) C++17
0 / 100
10 ms 3228 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1000002022;
int N, M;
vector<int> P, A;
vector<vector<int>> ch;
int add(int a, int b) {
    int c = a + b;
    if (c >= mod) {
        c -= mod;
    }
    return c;
}
int mul(int a, int b) {
    return 1LL * a * b % mod;
}
int sub(int a, int b) {
    int c = a - b;
    if (c < 0) {
        c += mod;
    }
    return c;
}
int cnt, cont;
bool bintree;
void init(int n, int m, vector<int> p, vector<int> a) {
    N = n, M = m;
    P = p, A = a;
    ch.resize(N);
    for (int i = 1; i < N + M; i++) {
        ch[P[i]].push_back(i);
    }
    bintree = 0;
    if (N + 1 == M && __builtin_popcount(M) == 1) {
        bintree = 1;
        for (int i = 1; i < N + M; i++) {
            if (P[i] != (i - 1) / 2) {
                bintree = 0;
            }
        }
        if (bintree) {
            cnt = 0;
            for (int i = 0; i < M; i++) {
                cnt += A[i];
            }
            int lg = __lg(M);
            cont = 1;
            int s = 1;
            for (int i = 0; i < lg; i++) {
                cont = mul(cont, s);
                s = mul(2, mul(s, s));
            }
            cout << cnt << " " << cont << "\n";
        }
    }
}
int count_ways(int L, int R) {
    for (int i = L; i <= R; i++) {
        A[i - N] ^= 1;
        cnt += A[i - N] == 1 ? 1 : -1;
    }
    if (bintree) {
        return mul(cnt, cont);
    }
    vector<int> tot(N + M), on(N + M), off(N + M);
    for (int i = N + M - 1; i >= 0; i--) {
        if (i >= N) {
            tot[i] = 1;
            if (A[i - N] == 0) {
                off[i] = 1;
            } else {
                on[i] = 1;
            }
        } else {
            int x = ch[i][0];
            int y = ch[i][1];
            tot[i] = mul(2, mul(tot[x], tot[y]));
            on[i] = add(mul(tot[x], on[y]), mul(tot[y], on[x]));
            off[i] = sub(tot[i], on[i]);
        }
    }
    return on[0];
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 3228 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 3228 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Possible tampering with the output or unexpected termination of the program
2 Halted 0 ms 0 KB -