답안 #1056623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056623 2024-08-13T10:22:15 Z vjudge1 디지털 회로 (IOI22_circuit) C++17
2 / 100
1772 ms 4184 KB
#include "circuit.h"

#include <bits/stdc++.h>
using namespace std;

using vi = vector<int>;
using ll = long long;
const int MOD = 1e9 + 2022;

vi W, A;
int n0;

void init(int n, int m, vi P, vi A0) {
    n0 = n;
    A = A0;
    vector<vi> G(n + m);
    vi NR(n + m, 0);
    for(int i = 1; i < n + m; ++i) {
        G[P[i]].push_back(i);
    }

    function<void(int)> dfs0 = [&](int u) {
        NR[u] = 1;
        if(u >= n) {
            return;
        }
        for(auto it : G[u]) {
            dfs0(it);
            NR[u] = 1ll * NR[u] * NR[it] % MOD;
        }
        NR[u] = 1ll * NR[u] * G[u].size() % MOD;
    };
    dfs0(0);

    W.resize(m, 0);
    function<void(int, int)> dfs = [&](int u, int v) {
        if(u >= n) {
            W[u - n] = v;
            return;
        }
        vi Pref, Suf;
        for(auto it : G[u]) {
            Pref.push_back(NR[it]);
            Suf.push_back(NR[it]);
        }
        int nr = Pref.size();
        for(int i = 1; i < nr; ++i)
            Pref[i] = 1ll * Pref[i - 1] * Pref[i] % MOD;
        for(int i = nr - 2; i >= 0; --i)
            Suf[i] = 1ll * Suf[i + 1] * Suf[i] % MOD;
        for(int i = 0; i < nr; ++i) {
            ll f = 1;
            if(i) f *= Pref[i - 1];
            if(i + 1 < nr) f *= Suf[i + 1];
            f %= MOD;
            dfs(G[u][i], f * v % MOD);
        }
    };
    dfs(0, 1);
}

int count_ways(int l, int r) {
    l -= n0; r -= n0;
    for(int i = l; i <= r; ++i) {
        A[i] ^= 1;
    }
    int re = 0;
    for(int i = 0; i < W.size(); ++i)
        re += W[i] * A[i];
    return re;
}

Compilation message

circuit.cpp: In function 'int count_ways(int, int)':
circuit.cpp:68:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int i = 0; i < W.size(); ++i)
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1772 ms 4184 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-747097920'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1772 ms 4184 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-747097920'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -