답안 #634887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634887 2022-08-25T08:11:20 Z keta_tsimakuridze 디지털 회로 (IOI22_circuit) C++17
18 / 100
3000 ms 7448 KB
#include "circuit.h"
#include <bits/stdc++.h>2
#define ll long long
using namespace std;
#include <vector>
const int N = 2e5 + 5, mod = 1000002022;
int sub[N], k[N], n, m, a[N];
vector<int> V[N];
void dfs(int u) {
    sub[u] = 1;
    if(V[u].size()) sub[u] = (ll)sub[u] * V[u].size() % mod;
    for(int i = 0; i < V[u].size(); i++) {
        dfs(V[u][i]);
        sub[u] = (ll)sub[u] * sub[V[u][i]] % mod;
    }
}
void dfs2(int u, int cur) {
    vector<int> p(V[u].size()), s(V[u].size());
    k[u] = cur;
    for(int i = 0; i < V[u].size(); i++) {
        p[i] = sub[V[u][i]];
        if(i) p[i] = (ll)p[i] * p[i - 1] % mod;
    }
    for(int i = (int)V[u].size() - 1; i >= 0; i--) {
        s[i] = sub[V[u][i]];
        if(i + 1 != V[u].size()) s[i] = (ll)s[i + 1] * s[i] % mod;
    }
    for(int i = 0; i < V[u].size(); i++) {
        int x = 1;
        if(i) x = (ll)x * p[i - 1] % mod;
        if(i + 1 != V[u].size()) x = (ll)x * s[i + 1] % mod;

        dfs2(V[u][i], (ll)cur * x % mod);
    }
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n = N, m = M;
    for(int i = 1; i < N + M; i++) {
        V[P[i]].push_back(i);
    }

    for(int i = N; i < N + M; i++) a[i] = A[i - N];

    dfs(0);
    dfs2(0, 1);
}

int count_ways(int L, int R) {


  for(int i = L; i <= R; i++) {
    a[i] ^= 1;
  }
  int ans = 0;
  for(int i = n; i < n + m; i++) {
    ans = (ans + (ll)a[i] * k[i] % mod) % mod;
  }
  return ans;
}

Compilation message

circuit.cpp:2:25: warning: extra tokens at end of #include directive
    2 | #include <bits/stdc++.h>2
      |                         ^
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0; i < V[u].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
circuit.cpp: In function 'void dfs2(int, int)':
circuit.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i = 0; i < V[u].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
circuit.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if(i + 1 != V[u].size()) s[i] = (ll)s[i + 1] * s[i] % mod;
      |            ~~~~~~^~~~~~~~~~~~~~
circuit.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i = 0; i < V[u].size(); i++) {
      |                    ~~^~~~~~~~~~~~~
circuit.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         if(i + 1 != V[u].size()) x = (ll)x * s[i + 1] % mod;
      |            ~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 4 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 2 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 5 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 4 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 2 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 5 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 4944 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 5 ms 5072 KB Output is correct
29 Correct 3 ms 4944 KB Output is correct
30 Correct 5 ms 4944 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 4 ms 4944 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 3 ms 4944 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 3 ms 4944 KB Output is correct
42 Correct 3 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3011 ms 7448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3011 ms 7448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 5 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Execution timed out 3011 ms 7448 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 4 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 2 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 5 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 4944 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 5 ms 5072 KB Output is correct
29 Correct 3 ms 4944 KB Output is correct
30 Correct 5 ms 4944 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 4 ms 4944 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 3 ms 4944 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 3 ms 4944 KB Output is correct
42 Correct 3 ms 4944 KB Output is correct
43 Correct 1388 ms 5200 KB Output is correct
44 Correct 1681 ms 5200 KB Output is correct
45 Correct 2168 ms 5256 KB Output is correct
46 Correct 2869 ms 5328 KB Output is correct
47 Execution timed out 3029 ms 5328 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 4 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 2 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 5 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 4944 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 5 ms 5072 KB Output is correct
29 Correct 3 ms 4944 KB Output is correct
30 Correct 5 ms 4944 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 4 ms 4944 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 3 ms 4944 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 3 ms 4944 KB Output is correct
42 Correct 3 ms 4944 KB Output is correct
43 Execution timed out 3011 ms 7448 KB Time limit exceeded
44 Halted 0 ms 0 KB -