Submission #1057809

# Submission time Handle Problem Language Result Execution time Memory
1057809 2024-08-14T06:21:13 Z aykhn Digital Circuit (IOI22_circuit) C++17
2 / 100
3000 ms 8404 KB
#include <bits/stdc++.h>
#include "circuit.h"

using namespace std;

const int MXN = 2e5 + 5;
const int mod = 1e9 + 2022;

int n, m;
vector<int> A;
vector<int> adj[MXN];
int dp[2][MXN];

void dfs(int a)
{
  dp[0][a] = dp[1][a] = 0;
  if (adj[a].empty())
  {
    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;
  for (int &v : adj[a])
  {
    dfs(v);
    for (int i = sz; i >= 0; i--)
    {
      dp1[i] = (dp1[i] * dp[0][v]) % mod;
      dp1[i] = (dp1[i] + ((dp1[i - 1] * dp[1][v]) % mod)) % mod;
    }
  }
  for (int i = 0; i <= sz; i++)
  {
    dp[0][a] = (dp[0][a] + (sz - i) * dp1[i]);
    dp[1][a] = (dp[1][a] +  i * dp1[i]);
  }
}

void init(int N, int M, vector<int> P, vector<int> AA) 
{
  A = AA;
  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);
}

int count_ways(int L, int 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 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 21 ms 6560 KB Output is correct
4 Correct 22 ms 6488 KB Output is correct
5 Correct 22 ms 6488 KB Output is correct
6 Correct 22 ms 6488 KB Output is correct
7 Correct 22 ms 6548 KB Output is correct
8 Correct 22 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Incorrect 1 ms 6488 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 21 ms 6560 KB Output is correct
4 Correct 22 ms 6488 KB Output is correct
5 Correct 22 ms 6488 KB Output is correct
6 Correct 22 ms 6488 KB Output is correct
7 Correct 22 ms 6548 KB Output is correct
8 Correct 22 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Incorrect 1 ms 6488 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3040 ms 8404 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3040 ms 8404 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Incorrect 1 ms 6488 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 21 ms 6560 KB Output is correct
4 Correct 22 ms 6488 KB Output is correct
5 Correct 22 ms 6488 KB Output is correct
6 Correct 22 ms 6488 KB Output is correct
7 Correct 22 ms 6548 KB Output is correct
8 Correct 22 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Incorrect 1 ms 6488 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 21 ms 6560 KB Output is correct
4 Correct 22 ms 6488 KB Output is correct
5 Correct 22 ms 6488 KB Output is correct
6 Correct 22 ms 6488 KB Output is correct
7 Correct 22 ms 6548 KB Output is correct
8 Correct 22 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Incorrect 1 ms 6488 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -