Submission #817183

# Submission time Handle Problem Language Result Execution time Memory
817183 2023-08-09T10:13:37 Z finn__ Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 7344 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

constexpr size_t N = 100000;
constexpr int64_t MOD = 1'000'002'022;

size_t n, m;
vector<size_t> g[2 * N];
bitset<2 * N> state;
int64_t f[2 * N][2];

void init(int n_, int m_, vector<int> p, vector<int> a)
{
    n = n_, m = m_;
    for (size_t i = 0; i < n + m; ++i)
        if (p[i] != -1)
            g[p[i]].push_back(i);
    for (size_t i = 0; i < m; ++i)
        state[n + i] = a[i], f[n + i][state[n + i]] = 1, f[n + i][!state[n + i]] = 0;
}

void dfs(size_t u)
{
    if (g[u].empty())
        return;

    size_t max_p = g[u].size();
    vector<int64_t> h(max_p + 1);
    h[0] = 1;
    for (auto const &v : g[u])
    {
        dfs(v);
        for (size_t i = max_p; i; --i)
            h[i] = (h[i] * f[v][0] + h[i - 1] * f[v][1]) % MOD;
        h[0] = (h[0] * f[v][0]) % MOD;
    }

    for (size_t i = max_p - 1; i; --i)
        h[i] += h[i + 1];
    f[u][1] = 0;
    for (size_t i = 1; i <= max_p; ++i)
        f[u][1] += h[i];
    f[u][1] %= MOD;

    f[u][0] = max_p;
    for (auto const &v : g[u])
        f[u][0] = (f[u][0] * (f[v][0] + f[v][1])) % MOD;
    f[u][0] = (f[u][0] - f[u][1] + MOD) % MOD;
}

int count_ways(int l, int r)
{
    for (size_t i = l; i <= r; ++i)
        state[i] = !state[i], f[i][state[i]] = 1, f[i][!state[i]] = 0;
    dfs(0);
    return f[0][1];
}

Compilation message

circuit.cpp: In function 'int count_ways(int, int)':
circuit.cpp:54:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |     for (size_t i = l; i <= r; ++i)
      |                        ~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 13 ms 4944 KB Output is correct
4 Correct 11 ms 4944 KB Output is correct
5 Correct 12 ms 4944 KB Output is correct
6 Correct 11 ms 4944 KB Output is correct
7 Correct 11 ms 4944 KB Output is correct
8 Correct 11 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4996 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 2 ms 4944 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 13 ms 4944 KB Output is correct
4 Correct 11 ms 4944 KB Output is correct
5 Correct 12 ms 4944 KB Output is correct
6 Correct 11 ms 4944 KB Output is correct
7 Correct 11 ms 4944 KB Output is correct
8 Correct 11 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4996 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 2 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 2 ms 4944 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 4972 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5012 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 11 ms 4944 KB Output is correct
30 Correct 12 ms 5040 KB Output is correct
31 Correct 3 ms 5192 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 4 ms 4944 KB Output is correct
36 Correct 3 ms 5220 KB Output is correct
37 Correct 12 ms 5200 KB Output is correct
38 Correct 12 ms 5220 KB Output is correct
39 Correct 3 ms 4944 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 2 ms 4944 KB Output is correct
42 Correct 3 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3083 ms 7344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3083 ms 7344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4996 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 2 ms 4944 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 4972 KB Output is correct
13 Execution timed out 3083 ms 7344 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 13 ms 4944 KB Output is correct
4 Correct 11 ms 4944 KB Output is correct
5 Correct 12 ms 4944 KB Output is correct
6 Correct 11 ms 4944 KB Output is correct
7 Correct 11 ms 4944 KB Output is correct
8 Correct 11 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4996 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 2 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 2 ms 4944 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 4972 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5012 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 11 ms 4944 KB Output is correct
30 Correct 12 ms 5040 KB Output is correct
31 Correct 3 ms 5192 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 4 ms 4944 KB Output is correct
36 Correct 3 ms 5220 KB Output is correct
37 Correct 12 ms 5200 KB Output is correct
38 Correct 12 ms 5220 KB Output is correct
39 Correct 3 ms 4944 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 2 ms 4944 KB Output is correct
42 Correct 3 ms 4944 KB Output is correct
43 Execution timed out 3073 ms 5200 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 13 ms 4944 KB Output is correct
4 Correct 11 ms 4944 KB Output is correct
5 Correct 12 ms 4944 KB Output is correct
6 Correct 11 ms 4944 KB Output is correct
7 Correct 11 ms 4944 KB Output is correct
8 Correct 11 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4996 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 2 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 2 ms 4944 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 4972 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5012 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 11 ms 4944 KB Output is correct
30 Correct 12 ms 5040 KB Output is correct
31 Correct 3 ms 5192 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 4 ms 4944 KB Output is correct
36 Correct 3 ms 5220 KB Output is correct
37 Correct 12 ms 5200 KB Output is correct
38 Correct 12 ms 5220 KB Output is correct
39 Correct 3 ms 4944 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 2 ms 4944 KB Output is correct
42 Correct 3 ms 4944 KB Output is correct
43 Execution timed out 3083 ms 7344 KB Time limit exceeded
44 Halted 0 ms 0 KB -