Submission #1051167

# Submission time Handle Problem Language Result Execution time Memory
1051167 2024-08-09T21:38:23 Z Trent Digital Circuit (IOI22_circuit) C++17
46 / 100
3000 ms 4696 KB
#include "circuit.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;

const ll MOD = 1000002022;
const int MN = 1e5 + 10;
vvi ch;
vll w;
int n, m;
vll totPos;
void sdfs(int c) {
  totPos[c] = c >= n ? 1 : ch[c].size();
  for(int i : ch[c]) {
    sdfs(i);
    totPos[c] = totPos[c] * totPos[i] % MOD;
  }
}
void dfs(int c, ll cw) {
  w[c] = cw;
  for(int i : ch[c]) {
    ll wCh = cw;
    for(int j : ch[c]) if(j != i) wCh = wCh * totPos[j] % MOD;
    dfs(i, wCh);
  }
}

vb tgl;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
  ::n = N, ::m = M;
  ch.resize(N+M);
  totPos.resize(N+M);
  w.resize(N+M);
  tgl.resize(N+M);

  REP(i, 1, N+M) ch[P[i]].push_back(i);
  sdfs(0);
  dfs(0, 1);
  forR(i, M) tgl[N+i] = A[i] == 1;
}

int count_ways(int L, int R) {
  REP(i, L, R+1) tgl[i] = !tgl[i];
  ll tot = 0;
  REP(i, n, n+m) if(tgl[i]) tot = (w[i] + tot) % MOD;
  return tot;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
4 Correct 4 ms 492 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 4 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 Correct 0 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 1 ms 344 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 0 ms 600 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 1 ms 344 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
4 Correct 4 ms 492 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 4 ms 492 KB Output is correct
30 Correct 4 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 2 ms 344 KB Output is correct
36 Correct 0 ms 600 KB Output is correct
37 Correct 4 ms 600 KB Output is correct
38 Correct 4 ms 624 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3057 ms 4696 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3057 ms 4696 KB Time limit exceeded
2 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 Correct 0 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 1 ms 344 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Execution timed out 3057 ms 4696 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
4 Correct 4 ms 492 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 4 ms 492 KB Output is correct
30 Correct 4 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 2 ms 344 KB Output is correct
36 Correct 0 ms 600 KB Output is correct
37 Correct 4 ms 600 KB Output is correct
38 Correct 4 ms 624 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 777 ms 852 KB Output is correct
44 Correct 1110 ms 856 KB Output is correct
45 Correct 1149 ms 856 KB Output is correct
46 Correct 1326 ms 1112 KB Output is correct
47 Correct 1658 ms 1112 KB Output is correct
48 Correct 1682 ms 1112 KB Output is correct
49 Correct 1710 ms 1112 KB Output is correct
50 Correct 2050 ms 1112 KB Output is correct
51 Correct 2126 ms 732 KB Output is correct
52 Correct 1788 ms 732 KB Output is correct
53 Correct 503 ms 1112 KB Output is correct
54 Correct 1710 ms 856 KB Output is correct
55 Correct 1710 ms 852 KB Output is correct
56 Correct 1668 ms 600 KB Output is correct
57 Correct 1641 ms 600 KB Output is correct
58 Correct 1731 ms 1368 KB Output is correct
59 Correct 1773 ms 1452 KB Output is correct
60 Correct 2077 ms 1452 KB Output is correct
61 Correct 1030 ms 856 KB Output is correct
62 Correct 1320 ms 600 KB Output is correct
63 Correct 1327 ms 600 KB Output is correct
64 Correct 1687 ms 600 KB Output is correct
65 Correct 473 ms 600 KB Output is correct
66 Correct 1428 ms 856 KB Output is correct
67 Correct 1517 ms 856 KB Output is correct
68 Correct 1772 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
4 Correct 4 ms 492 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 4 ms 492 KB Output is correct
30 Correct 4 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 2 ms 344 KB Output is correct
36 Correct 0 ms 600 KB Output is correct
37 Correct 4 ms 600 KB Output is correct
38 Correct 4 ms 624 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Execution timed out 3057 ms 4696 KB Time limit exceeded
44 Halted 0 ms 0 KB -