답안 #1057832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057832 2024-08-14T06:35:57 Z aykhn 디지털 회로 (IOI22_circuit) C++17
22 / 100
3000 ms 13904 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];

void calc(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])
  {
    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;
    }
  }
  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);
  dfs(0);
}

int32_t count_ways(int32_t L, int32_t R) {
  for (int i = L; i <= R; i++) A[i] ^= 1;
  if (L == R)
  {
    while (L != -1)
    {
      calc(L);
      L = P[L];
    }
  }
  else dfs(0);
  return dp[1][0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 8024 KB Output is correct
3 Correct 21 ms 8024 KB Output is correct
4 Correct 21 ms 8024 KB Output is correct
5 Correct 21 ms 8024 KB Output is correct
6 Correct 21 ms 8024 KB Output is correct
7 Correct 22 ms 8024 KB Output is correct
8 Correct 21 ms 8024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 1 ms 7924 KB Output is correct
3 Correct 1 ms 8024 KB Output is correct
4 Correct 2 ms 8024 KB Output is correct
5 Correct 1 ms 8024 KB Output is correct
6 Correct 2 ms 8160 KB Output is correct
7 Correct 2 ms 8024 KB Output is correct
8 Correct 2 ms 8024 KB Output is correct
9 Correct 2 ms 8024 KB Output is correct
10 Correct 2 ms 8024 KB Output is correct
11 Correct 2 ms 8024 KB Output is correct
12 Correct 2 ms 8024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 8024 KB Output is correct
3 Correct 21 ms 8024 KB Output is correct
4 Correct 21 ms 8024 KB Output is correct
5 Correct 21 ms 8024 KB Output is correct
6 Correct 21 ms 8024 KB Output is correct
7 Correct 22 ms 8024 KB Output is correct
8 Correct 21 ms 8024 KB Output is correct
9 Correct 2 ms 8024 KB Output is correct
10 Correct 1 ms 7924 KB Output is correct
11 Correct 1 ms 8024 KB Output is correct
12 Correct 2 ms 8024 KB Output is correct
13 Correct 1 ms 8024 KB Output is correct
14 Correct 2 ms 8160 KB Output is correct
15 Correct 2 ms 8024 KB Output is correct
16 Correct 2 ms 8024 KB Output is correct
17 Correct 2 ms 8024 KB Output is correct
18 Correct 2 ms 8024 KB Output is correct
19 Correct 2 ms 8024 KB Output is correct
20 Correct 2 ms 8024 KB Output is correct
21 Correct 2 ms 8024 KB Output is correct
22 Correct 2 ms 8024 KB Output is correct
23 Correct 2 ms 8024 KB Output is correct
24 Correct 2 ms 8024 KB Output is correct
25 Correct 2 ms 8024 KB Output is correct
26 Correct 2 ms 8024 KB Output is correct
27 Correct 2 ms 8024 KB Output is correct
28 Correct 2 ms 8024 KB Output is correct
29 Correct 21 ms 8144 KB Output is correct
30 Correct 21 ms 8144 KB Output is correct
31 Correct 2 ms 8108 KB Output is correct
32 Correct 2 ms 8024 KB Output is correct
33 Correct 2 ms 8024 KB Output is correct
34 Correct 2 ms 8024 KB Output is correct
35 Correct 5 ms 8024 KB Output is correct
36 Correct 2 ms 8024 KB Output is correct
37 Correct 23 ms 8236 KB Output is correct
38 Correct 22 ms 8024 KB Output is correct
39 Correct 2 ms 8024 KB Output is correct
40 Correct 2 ms 8024 KB Output is correct
41 Correct 2 ms 8024 KB Output is correct
42 Correct 2 ms 8024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 431 ms 10896 KB Output is correct
2 Correct 610 ms 13904 KB Output is correct
3 Correct 628 ms 13904 KB Output is correct
4 Correct 687 ms 13904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 431 ms 10896 KB Output is correct
2 Correct 610 ms 13904 KB Output is correct
3 Correct 628 ms 13904 KB Output is correct
4 Correct 687 ms 13904 KB Output is correct
5 Execution timed out 3033 ms 11092 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 1 ms 7924 KB Output is correct
3 Correct 1 ms 8024 KB Output is correct
4 Correct 2 ms 8024 KB Output is correct
5 Correct 1 ms 8024 KB Output is correct
6 Correct 2 ms 8160 KB Output is correct
7 Correct 2 ms 8024 KB Output is correct
8 Correct 2 ms 8024 KB Output is correct
9 Correct 2 ms 8024 KB Output is correct
10 Correct 2 ms 8024 KB Output is correct
11 Correct 2 ms 8024 KB Output is correct
12 Correct 2 ms 8024 KB Output is correct
13 Correct 431 ms 10896 KB Output is correct
14 Correct 610 ms 13904 KB Output is correct
15 Correct 628 ms 13904 KB Output is correct
16 Correct 687 ms 13904 KB Output is correct
17 Execution timed out 3033 ms 11092 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 8024 KB Output is correct
3 Correct 21 ms 8024 KB Output is correct
4 Correct 21 ms 8024 KB Output is correct
5 Correct 21 ms 8024 KB Output is correct
6 Correct 21 ms 8024 KB Output is correct
7 Correct 22 ms 8024 KB Output is correct
8 Correct 21 ms 8024 KB Output is correct
9 Correct 2 ms 8024 KB Output is correct
10 Correct 1 ms 7924 KB Output is correct
11 Correct 1 ms 8024 KB Output is correct
12 Correct 2 ms 8024 KB Output is correct
13 Correct 1 ms 8024 KB Output is correct
14 Correct 2 ms 8160 KB Output is correct
15 Correct 2 ms 8024 KB Output is correct
16 Correct 2 ms 8024 KB Output is correct
17 Correct 2 ms 8024 KB Output is correct
18 Correct 2 ms 8024 KB Output is correct
19 Correct 2 ms 8024 KB Output is correct
20 Correct 2 ms 8024 KB Output is correct
21 Correct 2 ms 8024 KB Output is correct
22 Correct 2 ms 8024 KB Output is correct
23 Correct 2 ms 8024 KB Output is correct
24 Correct 2 ms 8024 KB Output is correct
25 Correct 2 ms 8024 KB Output is correct
26 Correct 2 ms 8024 KB Output is correct
27 Correct 2 ms 8024 KB Output is correct
28 Correct 2 ms 8024 KB Output is correct
29 Correct 21 ms 8144 KB Output is correct
30 Correct 21 ms 8144 KB Output is correct
31 Correct 2 ms 8108 KB Output is correct
32 Correct 2 ms 8024 KB Output is correct
33 Correct 2 ms 8024 KB Output is correct
34 Correct 2 ms 8024 KB Output is correct
35 Correct 5 ms 8024 KB Output is correct
36 Correct 2 ms 8024 KB Output is correct
37 Correct 23 ms 8236 KB Output is correct
38 Correct 22 ms 8024 KB Output is correct
39 Correct 2 ms 8024 KB Output is correct
40 Correct 2 ms 8024 KB Output is correct
41 Correct 2 ms 8024 KB Output is correct
42 Correct 2 ms 8024 KB Output is correct
43 Execution timed out 3051 ms 8280 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Correct 2 ms 8024 KB Output is correct
3 Correct 21 ms 8024 KB Output is correct
4 Correct 21 ms 8024 KB Output is correct
5 Correct 21 ms 8024 KB Output is correct
6 Correct 21 ms 8024 KB Output is correct
7 Correct 22 ms 8024 KB Output is correct
8 Correct 21 ms 8024 KB Output is correct
9 Correct 2 ms 8024 KB Output is correct
10 Correct 1 ms 7924 KB Output is correct
11 Correct 1 ms 8024 KB Output is correct
12 Correct 2 ms 8024 KB Output is correct
13 Correct 1 ms 8024 KB Output is correct
14 Correct 2 ms 8160 KB Output is correct
15 Correct 2 ms 8024 KB Output is correct
16 Correct 2 ms 8024 KB Output is correct
17 Correct 2 ms 8024 KB Output is correct
18 Correct 2 ms 8024 KB Output is correct
19 Correct 2 ms 8024 KB Output is correct
20 Correct 2 ms 8024 KB Output is correct
21 Correct 2 ms 8024 KB Output is correct
22 Correct 2 ms 8024 KB Output is correct
23 Correct 2 ms 8024 KB Output is correct
24 Correct 2 ms 8024 KB Output is correct
25 Correct 2 ms 8024 KB Output is correct
26 Correct 2 ms 8024 KB Output is correct
27 Correct 2 ms 8024 KB Output is correct
28 Correct 2 ms 8024 KB Output is correct
29 Correct 21 ms 8144 KB Output is correct
30 Correct 21 ms 8144 KB Output is correct
31 Correct 2 ms 8108 KB Output is correct
32 Correct 2 ms 8024 KB Output is correct
33 Correct 2 ms 8024 KB Output is correct
34 Correct 2 ms 8024 KB Output is correct
35 Correct 5 ms 8024 KB Output is correct
36 Correct 2 ms 8024 KB Output is correct
37 Correct 23 ms 8236 KB Output is correct
38 Correct 22 ms 8024 KB Output is correct
39 Correct 2 ms 8024 KB Output is correct
40 Correct 2 ms 8024 KB Output is correct
41 Correct 2 ms 8024 KB Output is correct
42 Correct 2 ms 8024 KB Output is correct
43 Correct 431 ms 10896 KB Output is correct
44 Correct 610 ms 13904 KB Output is correct
45 Correct 628 ms 13904 KB Output is correct
46 Correct 687 ms 13904 KB Output is correct
47 Execution timed out 3033 ms 11092 KB Time limit exceeded
48 Halted 0 ms 0 KB -