Submission #787538

# Submission time Handle Problem Language Result Execution time Memory
787538 2023-07-19T09:23:41 Z thimote75 Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 3364 KB
#include "circuit.h"

#include <bits/stdc++.h>
#define num long long

using namespace std;
const int MOD = 1000002022;

using idata = vector<int>;
using ndata = vector<num>;
using igrid = vector<idata>;

ndata C;

idata status;
idata target;
igrid roads;

int N, M;

void init(int _N, int _M, idata P, idata A) {
  N = _N; M = _M;
  C    .resize(N);

  roads.resize(N);

  for (int i = 1; i < N + M; i ++)
    roads[P[i]].push_back(i);

  status = A;
  target.resize(M);
  for (int i = 0; i < M; i ++)
    target[i] = P[i + N];

  for (int i = 1; i < N + M; i ++) C[P[i]] ++;
}

pair<num, num> dfs (int node) {
  if (node >= N)
    return { 1 - status[node - N], status[node - N] };

  ndata grid(C[node] + 1, 0);
  grid[0] = 1;

  for (int next : roads[node]) {
    pair<num, num> res = dfs(next);

    for (int i = grid.size() - 1; i >= 0; i --) {
      if (i + 1 != grid.size()) {
        grid[i + 1] += grid[i] * res.second;
        grid[i + 1] %= MOD;
      }

      grid[i] *= res.first; grid[i] %= MOD;
    }
  }

  pair<num, num> result = { 0, 0 };
  for (int i = 1; i < grid.size(); i ++) {
    result.second += i * grid[i];
    result.second %= MOD;

    result.first += (grid.size() - i) * grid[i - 1];
    result.first %= MOD;
  }

  return result;
}

int count_ways(int L, int R) {
  L -= N; R -= N;
  for (int i = L; i <= R; i ++)
    status [i] = 1 - status[i];
  
  return dfs(0).second;
}

Compilation message

circuit.cpp: In function 'std::pair<long long int, long long int> dfs(int)':
circuit.cpp:49:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |       if (i + 1 != grid.size()) {
      |           ~~~~~~^~~~~~~~~~~~~~
circuit.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for (int i = 1; i < grid.size(); i ++) {
      |                   ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 14 ms 208 KB Output is correct
4 Correct 15 ms 208 KB Output is correct
5 Correct 18 ms 208 KB Output is correct
6 Correct 15 ms 208 KB Output is correct
7 Correct 15 ms 324 KB Output is correct
8 Correct 14 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 14 ms 208 KB Output is correct
4 Correct 15 ms 208 KB Output is correct
5 Correct 18 ms 208 KB Output is correct
6 Correct 15 ms 208 KB Output is correct
7 Correct 15 ms 324 KB Output is correct
8 Correct 14 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 2 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 352 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 15 ms 208 KB Output is correct
30 Correct 15 ms 208 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 392 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 3 ms 208 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
37 Correct 15 ms 492 KB Output is correct
38 Correct 15 ms 464 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3021 ms 3364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3021 ms 3364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Execution timed out 3021 ms 3364 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 14 ms 208 KB Output is correct
4 Correct 15 ms 208 KB Output is correct
5 Correct 18 ms 208 KB Output is correct
6 Correct 15 ms 208 KB Output is correct
7 Correct 15 ms 324 KB Output is correct
8 Correct 14 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 2 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 352 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 15 ms 208 KB Output is correct
30 Correct 15 ms 208 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 392 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 3 ms 208 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
37 Correct 15 ms 492 KB Output is correct
38 Correct 15 ms 464 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 208 KB Output is correct
43 Execution timed out 3035 ms 464 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 14 ms 208 KB Output is correct
4 Correct 15 ms 208 KB Output is correct
5 Correct 18 ms 208 KB Output is correct
6 Correct 15 ms 208 KB Output is correct
7 Correct 15 ms 324 KB Output is correct
8 Correct 14 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 2 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 352 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 15 ms 208 KB Output is correct
30 Correct 15 ms 208 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 392 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 3 ms 208 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
37 Correct 15 ms 492 KB Output is correct
38 Correct 15 ms 464 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 208 KB Output is correct
43 Execution timed out 3021 ms 3364 KB Time limit exceeded
44 Halted 0 ms 0 KB -