Submission #1057904

# Submission time Handle Problem Language Result Execution time Memory
1057904 2024-08-14T07:14:51 Z aykhn Digital Circuit (IOI22_circuit) C++17
2 / 100
17 ms 27340 KB
#include <bits/stdc++.h>
#include "circuit.h"
 
using namespace std;
 
#define int long long
 
const int MXN = 2e5 + 5;
const int mod = 1e9 + 2022;
 
int n, m;
vector<int> A, P;
vector<int> adj[MXN];
int dp[2][MXN];
int l[MXN], r[MXN];
 
void calc(int a)
{
  l[a] = n + m + 100, r[a] = -n - m - 100;
  dp[0][a] = dp[1][a] = 0;
  if (adj[a].empty())
  {
    l[a] = r[a] = a;
    dp[0][a] = A[a] ^ 1;
    dp[1][a] = A[a];
    return;
  }
  int sz = adj[a].size();
  vector<int> dp1(sz + 1, 0);
  dp1[0] = 1;
  int cnt = 0;
  for (int &v : adj[a])
  {
    cnt += r[v] - l[v] + 1;
    l[a] = min(l[a], l[v]);
    r[a] = max(r[a], r[v]);
    for (int i = sz; i >= 0; i--)
    {
      dp1[i] = (dp1[i] * dp[0][v]) % mod;
      if (i) dp1[i] = (dp1[i] + ((dp1[i - 1] * dp[1][v]) % mod)) % mod;
    }
  }
  assert(cnt == r[a] - l[a] + 1);
  for (int i = 0; i <= sz; i++)
  {
    dp[0][a] = (dp[0][a] + (((sz - i) * dp1[i]) % mod)) % mod;
    dp[1][a] = (dp[1][a] +  ((i * dp1[i]) % mod)) % mod;
  }
}
 
void dfs(int a)
{
  for (int &v : adj[a])
  {
    dfs(v);
  }
  calc(a);
}
 
void init(int32_t N, int32_t M, vector<int32_t> PP, vector<int32_t> AA) 
{
  for (int32_t &i : PP) P.push_back(i);
  for (int32_t &i : AA) A.push_back(i);
  reverse(A.begin(), A.end());
  A.resize(N + M, 0);
  reverse(A.begin(), A.end());
  for (int i = 1; i < N + M; i++) adj[P[i]].push_back(i);
}
 
int32_t count_ways(int32_t L, int32_t R) {
  for (int i = L; i <= R; i++) A[i] ^= 1;
  dfs(0);
  return dp[1][0];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 2 ms 11096 KB Output is correct
3 Correct 14 ms 11096 KB Output is correct
4 Correct 16 ms 11096 KB Output is correct
5 Correct 15 ms 11096 KB Output is correct
6 Correct 15 ms 11096 KB Output is correct
7 Correct 17 ms 11280 KB Output is correct
8 Correct 15 ms 11092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Runtime error 7 ms 22360 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 2 ms 11096 KB Output is correct
3 Correct 14 ms 11096 KB Output is correct
4 Correct 16 ms 11096 KB Output is correct
5 Correct 15 ms 11096 KB Output is correct
6 Correct 15 ms 11096 KB Output is correct
7 Correct 17 ms 11280 KB Output is correct
8 Correct 15 ms 11092 KB Output is correct
9 Correct 2 ms 11096 KB Output is correct
10 Runtime error 7 ms 22360 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 27340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 27340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Runtime error 7 ms 22360 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 2 ms 11096 KB Output is correct
3 Correct 14 ms 11096 KB Output is correct
4 Correct 16 ms 11096 KB Output is correct
5 Correct 15 ms 11096 KB Output is correct
6 Correct 15 ms 11096 KB Output is correct
7 Correct 17 ms 11280 KB Output is correct
8 Correct 15 ms 11092 KB Output is correct
9 Correct 2 ms 11096 KB Output is correct
10 Runtime error 7 ms 22360 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11096 KB Output is correct
2 Correct 2 ms 11096 KB Output is correct
3 Correct 14 ms 11096 KB Output is correct
4 Correct 16 ms 11096 KB Output is correct
5 Correct 15 ms 11096 KB Output is correct
6 Correct 15 ms 11096 KB Output is correct
7 Correct 17 ms 11280 KB Output is correct
8 Correct 15 ms 11092 KB Output is correct
9 Correct 2 ms 11096 KB Output is correct
10 Runtime error 7 ms 22360 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -