Submission #630128

# Submission time Handle Problem Language Result Execution time Memory
630128 2022-08-15T17:48:23 Z flashmt Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 15012 KB
#include <bits/stdc++.h>
#include "circuit.h"
using namespace std;
const int BASE = 1e9 + 2022;
const int N = 100100;

int n, m;
vector<int> a[N];
vector<int> states;
vector<long long> coef, ways;
long long ans;

void dfsWay(int x)
{
  if (empty(a[x]))
    return;
  for (int y : a[x])
  {
    dfsWay(y);
    ways[x] *= ways[y];
    ways[x] %= BASE;
  }
  ways[x] *= size(a[x]);
  ways[x] %= BASE;
}

void dfsCoef(int x)
{
  vector<long long> prefix(size(a[x]));
  for (int i = 0; i < size(a[x]); i++)
  {
    prefix[i] = ways[a[x][i]];
    if (i)
      prefix[i] = prefix[i] * prefix[i - 1] % BASE;
  }

  long long suffix = 1;
  for (int i = int(size(a[x])) - 1; i >= 0; i--)
  {
    int y = a[x][i];
    coef[y] = suffix;
    if (i)
      coef[y] = coef[y] * prefix[i - 1] % BASE;
    suffix *= ways[y];
    suffix %= BASE;
  }

  for (int y : a[x])
  {
    coef[y] = coef[y] * coef[x] % BASE;
    dfsCoef(y);
  }
}

void init(int N, int M, vector<int> P, vector<int> A)
{
  n = N;
  m = M;
  for (int i = 1; i < n + m; i++)
    a[P[i]].push_back(i);
  states = A;
  ways.assign(n + m, 1);
  dfsWay(0);
  coef.assign(n + m, 1);
  dfsCoef(0);
  for (int i = 0; i < m; i++)
    if (states[i])
      ans = (ans + coef[n + i]) % BASE;
}

int count_ways(int L, int R)
{
  for (int i = L; i <= R; i++)
  {
    states[i - n] ^= 1;
    if (states[i - n]) ans = (ans + coef[i]) % BASE;
    else ans = (ans - coef[i] + BASE) % BASE;
  }
  return ans;
}

Compilation message

circuit.cpp: In function 'void dfsCoef(int)':
circuit.cpp:30:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for (int i = 0; i < size(a[x]); i++)
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2648 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 2 ms 2648 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 3 ms 2672 KB Output is correct
10 Correct 2 ms 2824 KB Output is correct
11 Correct 3 ms 2768 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2648 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 2 ms 2648 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 3 ms 2672 KB Output is correct
18 Correct 2 ms 2824 KB Output is correct
19 Correct 3 ms 2768 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2656 KB Output is correct
23 Correct 3 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 3 ms 2640 KB Output is correct
26 Correct 3 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 2 ms 2768 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 3 ms 2768 KB Output is correct
37 Correct 3 ms 2768 KB Output is correct
38 Correct 3 ms 2784 KB Output is correct
39 Correct 2 ms 2640 KB Output is correct
40 Correct 2 ms 2640 KB Output is correct
41 Correct 2 ms 2640 KB Output is correct
42 Correct 2 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 688 ms 5584 KB Output is correct
2 Runtime error 33 ms 15012 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 688 ms 5584 KB Output is correct
2 Runtime error 33 ms 15012 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 3 ms 2672 KB Output is correct
10 Correct 2 ms 2824 KB Output is correct
11 Correct 3 ms 2768 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 688 ms 5584 KB Output is correct
14 Runtime error 33 ms 15012 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2648 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 2 ms 2648 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 3 ms 2672 KB Output is correct
18 Correct 2 ms 2824 KB Output is correct
19 Correct 3 ms 2768 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2656 KB Output is correct
23 Correct 3 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 3 ms 2640 KB Output is correct
26 Correct 3 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 2 ms 2768 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 3 ms 2768 KB Output is correct
37 Correct 3 ms 2768 KB Output is correct
38 Correct 3 ms 2784 KB Output is correct
39 Correct 2 ms 2640 KB Output is correct
40 Correct 2 ms 2640 KB Output is correct
41 Correct 2 ms 2640 KB Output is correct
42 Correct 2 ms 2640 KB Output is correct
43 Correct 1116 ms 2896 KB Output is correct
44 Correct 1569 ms 2896 KB Output is correct
45 Correct 1510 ms 2896 KB Output is correct
46 Correct 566 ms 3024 KB Output is correct
47 Correct 2122 ms 3024 KB Output is correct
48 Correct 2098 ms 3024 KB Output is correct
49 Correct 2154 ms 3024 KB Output is correct
50 Execution timed out 3008 ms 3024 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2648 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 2 ms 2648 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 3 ms 2672 KB Output is correct
18 Correct 2 ms 2824 KB Output is correct
19 Correct 3 ms 2768 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2656 KB Output is correct
23 Correct 3 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 3 ms 2640 KB Output is correct
26 Correct 3 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 2 ms 2768 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2640 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 3 ms 2768 KB Output is correct
37 Correct 3 ms 2768 KB Output is correct
38 Correct 3 ms 2784 KB Output is correct
39 Correct 2 ms 2640 KB Output is correct
40 Correct 2 ms 2640 KB Output is correct
41 Correct 2 ms 2640 KB Output is correct
42 Correct 2 ms 2640 KB Output is correct
43 Correct 688 ms 5584 KB Output is correct
44 Runtime error 33 ms 15012 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -