Submission #1074663

# Submission time Handle Problem Language Result Execution time Memory
1074663 2024-08-25T11:53:54 Z Zicrus Digital Circuit (IOI22_circuit) C++17
11 / 100
3000 ms 7608 KB
#include <bits/stdc++.h>
#include "circuit.h"
using namespace std;

typedef long long ll;

int n, m;
vector<int> p, a, mark;
vector<vector<int>> adj;
vector<vector<ll>> dp;

ll getDp(int state, int i) {
    if (i >= n) return state == a[i-n];
    return dp[state][i];
}

void update(int i) {
    ll numOff = 0, numOn = 0;
    for (ll mask = 0; mask < (1ll << adj[i].size()); mask++) {
        ll valOff = adj[i].size() - __builtin_popcount(mask);
        ll valOn = __builtin_popcount(mask);
        for (int b = 0; b < adj[i].size(); b++) {
            valOff *= getDp((mask >> b) & 1, adj[i][b]);
            valOn *= getDp((mask >> b) & 1, adj[i][b]);
            valOff %= 1000002022;
            valOn %= 1000002022;
        }
        numOff += valOff;
        numOn += valOn;
        numOff %= 1000002022;
        numOn %= 1000002022;
    }
    dp[0][i] = numOff;
    dp[1][i] = numOn;
}

void init(int N, int M, vector<int> P, vector<int> A) {
    n = N, m = M; p = P; a = A;
    mark = vector<int>(n);
    adj = vector<vector<int>>(n);
    dp = vector<vector<ll>>(2, vector<ll>(n));
    for (int i = 1; i < n+m; i++) {
        adj[p[i]].push_back(i);
    }
    for (int i = n-1; i >= 0; i--) {
        update(i);
    }
}

int count_ways(int L, int R) {
    L -= n; R -= n;
    priority_queue<int> q;
    for (int i = L; i <= R; i++) {
        a[i] = !a[i];
        int cur = p[n+i];
        while (cur != -1 && !mark[cur]) {
            mark[cur] = true;
            q.push({cur});
            cur = p[cur];
        }
    }
    while (!q.empty()) {
        int cur = q.top(); q.pop();
        update(cur);
        mark[cur] = false;
    }
    return dp[1][0];
}

#ifdef TEST
#include "grader.cpp"
#endif

Compilation message

circuit.cpp: In function 'void update(int)':
circuit.cpp:22:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for (int b = 0; b < adj[i].size(); b++) {
      |                         ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 105 ms 344 KB 1st lines differ - on the 1st token, expected: '509', found: '0'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 420 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 105 ms 344 KB 1st lines differ - on the 1st token, expected: '509', found: '0'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 576 ms 3924 KB Output is correct
2 Correct 763 ms 7508 KB Output is correct
3 Correct 809 ms 7508 KB Output is correct
4 Correct 782 ms 7608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 576 ms 3924 KB Output is correct
2 Correct 763 ms 7508 KB Output is correct
3 Correct 809 ms 7508 KB Output is correct
4 Correct 782 ms 7608 KB Output is correct
5 Execution timed out 3003 ms 4164 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 420 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 576 ms 3924 KB Output is correct
14 Correct 763 ms 7508 KB Output is correct
15 Correct 809 ms 7508 KB Output is correct
16 Correct 782 ms 7608 KB Output is correct
17 Execution timed out 3003 ms 4164 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 105 ms 344 KB 1st lines differ - on the 1st token, expected: '509', found: '0'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 105 ms 344 KB 1st lines differ - on the 1st token, expected: '509', found: '0'
4 Halted 0 ms 0 KB -