Submission #1034237

# Submission time Handle Problem Language Result Execution time Memory
1034237 2024-07-25T11:06:47 Z Mr_Husanboy Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 4184 KB
#include "circuit.h"
#include <bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()
#define ll long long
const int mod = 1000002022;

vector<int> state, p;
int n, m; 
vector<vector<int>> g;
template<typename T>
int len(T &a){return a.size();}


vector<array<ll, 2>> dp;



void init(int N, int M, std::vector<int> P, std::vector<int> A) {
  n = N, m = M;
  g.resize(n);
  state = A;
  p = P;
  for(int i = 1; i < n + m; i ++){
    g[p[i]].push_back(i);
  }
  dp.resize(n + m);
}

void dfs(int i){
  if(i >= n){
    dp[i][0] = state[i - n] ^ 1;
    dp[i][1] = state[i - n];
    return;
  }
  for(auto u : g[i]) dfs(u);
  vector<ll> prep(len(g[i]) + 1);
  prep[0] = 1;
  ll al = len(g[i]);
  int cur = 0;
  for(auto u : g[i]){
    cur ++;
    al = al * (dp[u][0] + dp[u][1]) % mod;
    for(int j = cur; j >= 0; j --){
      prep[j] = prep[j] * dp[u][0] % mod;
      if(j) prep[j] += prep[j - 1] * dp[u][1] % mod;
    }
  }
  dp[i][1] = 0;
  for(int j = 1; j <= len(g[i]); j ++){
    //cout << prep[j] * j << endl;
    dp[i][1] = (dp[i][1] + prep[j] * j) % mod;
  }

  dp[i][0] = al - dp[i][1];
  if(dp[i][0] < 0) dp[i][0] += mod;
}

int count_ways(int l, int r) {
  l -= n; r -= n;
  for(int i = l; i <= r; i ++) state[i] ^= 1;
  //for(int i = 0; i < m; i ++) cout << state[i] << ' ';
  dfs(0);
  return dp[0][1];
}
# 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 7 ms 472 KB Output is correct
4 Correct 9 ms 344 KB Output is correct
5 Correct 7 ms 472 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 8 ms 344 KB Output is correct
8 Correct 8 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 500 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 408 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 344 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 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 0 ms 344 KB Output is correct
3 Correct 7 ms 472 KB Output is correct
4 Correct 9 ms 344 KB Output is correct
5 Correct 7 ms 472 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 8 ms 344 KB Output is correct
8 Correct 8 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 500 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 408 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 8 ms 344 KB Output is correct
30 Correct 7 ms 344 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 2 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 7 ms 600 KB Output is correct
38 Correct 7 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3023 ms 4184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3023 ms 4184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 500 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 408 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 344 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Execution timed out 3023 ms 4184 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 0 ms 344 KB Output is correct
3 Correct 7 ms 472 KB Output is correct
4 Correct 9 ms 344 KB Output is correct
5 Correct 7 ms 472 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 8 ms 344 KB Output is correct
8 Correct 8 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 500 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 408 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 8 ms 344 KB Output is correct
30 Correct 7 ms 344 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 2 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 7 ms 600 KB Output is correct
38 Correct 7 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Execution timed out 3059 ms 600 KB Time limit exceeded
44 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 7 ms 472 KB Output is correct
4 Correct 9 ms 344 KB Output is correct
5 Correct 7 ms 472 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 8 ms 344 KB Output is correct
8 Correct 8 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 500 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 408 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 8 ms 344 KB Output is correct
30 Correct 7 ms 344 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 2 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 7 ms 600 KB Output is correct
38 Correct 7 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Execution timed out 3023 ms 4184 KB Time limit exceeded
44 Halted 0 ms 0 KB -