답안 #797600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
797600 2023-07-29T17:06:57 Z jakobrs 디지털 회로 (IOI22_circuit) C++17
0 / 100
11 ms 5576 KB
#include <iostream>
#include <vector>

using i64 = int64_t;

int n, m;
std::vector<int> p, a;

std::vector<std::vector<int>> children;

const i64 MOD = 1'000'002'022;

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n = N;
    m = M;
    p = P;
    a = A;

    children.resize(N);
    for (i64 i = 1; i < N + M; i++) {
        children[P[i]].push_back(i);
    }
}

auto dfs(int node) -> std::pair<i64, i64> {
    if (node >= n) {
        return {a[node - n] ? 1 : 0, 1};
    }

    i64 cs = children[node].size();
    std::vector<std::pair<i64, i64>> results;
    results.reserve(cs);

    for (i64 c : children[node]) {
        results.push_back(dfs(c));
    }

    std::vector<i64> xs_left {1}, xs_right {1};
    xs_left.reserve(cs);
    xs_right.reserve(cs);

    for (i64 i = 0; i < cs; i++) {
        xs_left.push_back(xs_left.back() * results[i].second % MOD);
        xs_right.push_back(xs_right.back() * results[cs - i - 1].second % MOD);
    }

    i64 sum = 0, of = cs;

    for (i64 i = 0; i < cs; i++) {
        sum += results[i].first * xs_left[i] % MOD * xs_right[n - i - 1];
        cs *= results[i].second;

        sum %= MOD;
        cs %= MOD;
    }

    return {sum, of};
}

int count_ways(int l, int r) {
    r += 1;

    l -= n;
    r -= n;

    for (i64 i = l; i < r; i++) {
        a[i] = !a[i];
    }

    return dfs(0).first;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB 2nd lines differ - on the 1st token, expected: '2', found: '50'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB 2nd lines differ - on the 1st token, expected: '2', found: '50'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB 2nd lines differ - on the 1st token, expected: '2', found: '50'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 5576 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 5576 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB 2nd lines differ - on the 1st token, expected: '2', found: '50'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB 2nd lines differ - on the 1st token, expected: '2', found: '50'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 208 KB 2nd lines differ - on the 1st token, expected: '2', found: '50'
2 Halted 0 ms 0 KB -