답안 #757153

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757153 2023-06-12T17:51:23 Z boris_mihov 디지털 회로 (IOI22_circuit) C++17
46 / 100
3000 ms 19448 KB
#include "circuit.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
 
typedef long long llong;
const int MAXN = 200000 + 10;
const int MOD = 1000002022;
const int INF = 1e9;
 
int n, m;
llong w[MAXN];
llong b[MAXN];
llong pw[MAXN];
llong multBy[MAXN];
std::vector <int> g[MAXN];
std::vector <int> prefixPW[MAXN];
std::vector <int> suffixPW[MAXN];

void initDFS(int node)
{
    if (g[node].empty())
    {
        pw[node] = 1;
        return;
    }
    
    pw[node] = g[node].size();
    for (const int &i : g[node])
    {
        initDFS(i);
        pw[node] *= pw[i];
        pw[node] %= MOD;
    }

    prefixPW[node].resize(g[node].size());
    prefixPW[node][0] = 1;

    for (int i = 1 ; i < g[node].size() ; ++i)
    {
        prefixPW[node][i] = (prefixPW[node][i - 1] * pw[g[node][i - 1]]) % MOD;
    }

    suffixPW[node].resize(g[node].size());
    suffixPW[node][g[node].size() - 1] = 1;
    for (int i = (int)g[node].size() - 2 ; i >= 0 ; --i)
    {
        suffixPW[node][i] = (suffixPW[node][i + 1] * pw[g[node][i + 1]]) % MOD;
    }
}

void findMult(int node, llong mult)
{
    if (g[node].empty())
    {
        multBy[node] = mult;
        return;
    }
    
    for (int i = 0 ; i < g[node].size() ; ++i)
    {
        findMult(g[node][i], (((mult * prefixPW[node][i]) % MOD) * suffixPW[node][i]) % 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)
    {
        g[P[i] + 1].push_back(i + 1);
    }
 
    for (int i = n + 1 ; i <= n + m ; ++i)
    {
        if (A[i - n - 1] == 0)
        {
            w[i] = 1;
            b[i] = 0;
        } else
        {
            b[i] = 1;
            w[i] = 0;
        }
    }

    initDFS(1);
    findMult(1, 1);
}
 
int count_ways(int L, int R) 
{
    L++; R++;
    for (int i = L ; i <= R ; ++i)
    {
        std::swap(b[i], w[i]);
    }
 
    llong res = 0;
    for (int i = n + 1 ; i <= n + m ; ++i)
    {
        res += multBy[i] * b[i];
        if (res >= MOD) res -= MOD;
    }

    return res;
}

Compilation message

circuit.cpp: In function 'void initDFS(int)':
circuit.cpp:40:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i = 1 ; i < g[node].size() ; ++i)
      |                      ~~^~~~~~~~~~~~~~~~
circuit.cpp: In function 'void findMult(int, llong)':
circuit.cpp:61:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for (int i = 0 ; i < g[node].size() ; ++i)
      |                      ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 8 ms 14376 KB Output is correct
3 Correct 8 ms 14400 KB Output is correct
4 Correct 8 ms 14400 KB Output is correct
5 Correct 8 ms 14416 KB Output is correct
6 Correct 8 ms 14364 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 9 ms 14416 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 8 ms 14424 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 8 ms 14464 KB Output is correct
7 Correct 9 ms 14544 KB Output is correct
8 Correct 8 ms 14544 KB Output is correct
9 Correct 9 ms 14544 KB Output is correct
10 Correct 8 ms 14544 KB Output is correct
11 Correct 8 ms 14544 KB Output is correct
12 Correct 8 ms 14484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 8 ms 14376 KB Output is correct
3 Correct 8 ms 14400 KB Output is correct
4 Correct 8 ms 14400 KB Output is correct
5 Correct 8 ms 14416 KB Output is correct
6 Correct 8 ms 14364 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14416 KB Output is correct
9 Correct 7 ms 14416 KB Output is correct
10 Correct 9 ms 14416 KB Output is correct
11 Correct 8 ms 14416 KB Output is correct
12 Correct 8 ms 14424 KB Output is correct
13 Correct 9 ms 14416 KB Output is correct
14 Correct 8 ms 14464 KB Output is correct
15 Correct 9 ms 14544 KB Output is correct
16 Correct 8 ms 14544 KB Output is correct
17 Correct 9 ms 14544 KB Output is correct
18 Correct 8 ms 14544 KB Output is correct
19 Correct 8 ms 14544 KB Output is correct
20 Correct 8 ms 14484 KB Output is correct
21 Correct 9 ms 14544 KB Output is correct
22 Correct 10 ms 14416 KB Output is correct
23 Correct 9 ms 14416 KB Output is correct
24 Correct 9 ms 14544 KB Output is correct
25 Correct 9 ms 14544 KB Output is correct
26 Correct 9 ms 14544 KB Output is correct
27 Correct 9 ms 14544 KB Output is correct
28 Correct 9 ms 14544 KB Output is correct
29 Correct 8 ms 14416 KB Output is correct
30 Correct 8 ms 14416 KB Output is correct
31 Correct 9 ms 14544 KB Output is correct
32 Correct 11 ms 14544 KB Output is correct
33 Correct 8 ms 14404 KB Output is correct
34 Correct 8 ms 14416 KB Output is correct
35 Correct 9 ms 14416 KB Output is correct
36 Correct 11 ms 14544 KB Output is correct
37 Correct 9 ms 14544 KB Output is correct
38 Correct 9 ms 14544 KB Output is correct
39 Correct 9 ms 14416 KB Output is correct
40 Correct 9 ms 14480 KB Output is correct
41 Correct 8 ms 14416 KB Output is correct
42 Correct 8 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3052 ms 19448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3052 ms 19448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 9 ms 14416 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 8 ms 14424 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 8 ms 14464 KB Output is correct
7 Correct 9 ms 14544 KB Output is correct
8 Correct 8 ms 14544 KB Output is correct
9 Correct 9 ms 14544 KB Output is correct
10 Correct 8 ms 14544 KB Output is correct
11 Correct 8 ms 14544 KB Output is correct
12 Correct 8 ms 14484 KB Output is correct
13 Execution timed out 3052 ms 19448 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 8 ms 14376 KB Output is correct
3 Correct 8 ms 14400 KB Output is correct
4 Correct 8 ms 14400 KB Output is correct
5 Correct 8 ms 14416 KB Output is correct
6 Correct 8 ms 14364 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14416 KB Output is correct
9 Correct 7 ms 14416 KB Output is correct
10 Correct 9 ms 14416 KB Output is correct
11 Correct 8 ms 14416 KB Output is correct
12 Correct 8 ms 14424 KB Output is correct
13 Correct 9 ms 14416 KB Output is correct
14 Correct 8 ms 14464 KB Output is correct
15 Correct 9 ms 14544 KB Output is correct
16 Correct 8 ms 14544 KB Output is correct
17 Correct 9 ms 14544 KB Output is correct
18 Correct 8 ms 14544 KB Output is correct
19 Correct 8 ms 14544 KB Output is correct
20 Correct 8 ms 14484 KB Output is correct
21 Correct 9 ms 14544 KB Output is correct
22 Correct 10 ms 14416 KB Output is correct
23 Correct 9 ms 14416 KB Output is correct
24 Correct 9 ms 14544 KB Output is correct
25 Correct 9 ms 14544 KB Output is correct
26 Correct 9 ms 14544 KB Output is correct
27 Correct 9 ms 14544 KB Output is correct
28 Correct 9 ms 14544 KB Output is correct
29 Correct 8 ms 14416 KB Output is correct
30 Correct 8 ms 14416 KB Output is correct
31 Correct 9 ms 14544 KB Output is correct
32 Correct 11 ms 14544 KB Output is correct
33 Correct 8 ms 14404 KB Output is correct
34 Correct 8 ms 14416 KB Output is correct
35 Correct 9 ms 14416 KB Output is correct
36 Correct 11 ms 14544 KB Output is correct
37 Correct 9 ms 14544 KB Output is correct
38 Correct 9 ms 14544 KB Output is correct
39 Correct 9 ms 14416 KB Output is correct
40 Correct 9 ms 14480 KB Output is correct
41 Correct 8 ms 14416 KB Output is correct
42 Correct 8 ms 14416 KB Output is correct
43 Correct 1044 ms 14800 KB Output is correct
44 Correct 1535 ms 14988 KB Output is correct
45 Correct 1426 ms 14912 KB Output is correct
46 Correct 1743 ms 15128 KB Output is correct
47 Correct 2049 ms 15184 KB Output is correct
48 Correct 1971 ms 15164 KB Output is correct
49 Correct 1897 ms 15184 KB Output is correct
50 Correct 2216 ms 15184 KB Output is correct
51 Correct 2179 ms 14672 KB Output is correct
52 Correct 1911 ms 14672 KB Output is correct
53 Correct 770 ms 15280 KB Output is correct
54 Correct 1836 ms 15184 KB Output is correct
55 Correct 1610 ms 14880 KB Output is correct
56 Correct 2139 ms 14800 KB Output is correct
57 Correct 1696 ms 14676 KB Output is correct
58 Correct 1618 ms 15556 KB Output is correct
59 Correct 1801 ms 15660 KB Output is correct
60 Correct 2050 ms 15544 KB Output is correct
61 Correct 1412 ms 15036 KB Output is correct
62 Correct 1478 ms 14768 KB Output is correct
63 Correct 1635 ms 14672 KB Output is correct
64 Correct 1824 ms 14652 KB Output is correct
65 Correct 629 ms 14672 KB Output is correct
66 Correct 1600 ms 15032 KB Output is correct
67 Correct 1439 ms 15056 KB Output is correct
68 Correct 1742 ms 15056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 8 ms 14376 KB Output is correct
3 Correct 8 ms 14400 KB Output is correct
4 Correct 8 ms 14400 KB Output is correct
5 Correct 8 ms 14416 KB Output is correct
6 Correct 8 ms 14364 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14416 KB Output is correct
9 Correct 7 ms 14416 KB Output is correct
10 Correct 9 ms 14416 KB Output is correct
11 Correct 8 ms 14416 KB Output is correct
12 Correct 8 ms 14424 KB Output is correct
13 Correct 9 ms 14416 KB Output is correct
14 Correct 8 ms 14464 KB Output is correct
15 Correct 9 ms 14544 KB Output is correct
16 Correct 8 ms 14544 KB Output is correct
17 Correct 9 ms 14544 KB Output is correct
18 Correct 8 ms 14544 KB Output is correct
19 Correct 8 ms 14544 KB Output is correct
20 Correct 8 ms 14484 KB Output is correct
21 Correct 9 ms 14544 KB Output is correct
22 Correct 10 ms 14416 KB Output is correct
23 Correct 9 ms 14416 KB Output is correct
24 Correct 9 ms 14544 KB Output is correct
25 Correct 9 ms 14544 KB Output is correct
26 Correct 9 ms 14544 KB Output is correct
27 Correct 9 ms 14544 KB Output is correct
28 Correct 9 ms 14544 KB Output is correct
29 Correct 8 ms 14416 KB Output is correct
30 Correct 8 ms 14416 KB Output is correct
31 Correct 9 ms 14544 KB Output is correct
32 Correct 11 ms 14544 KB Output is correct
33 Correct 8 ms 14404 KB Output is correct
34 Correct 8 ms 14416 KB Output is correct
35 Correct 9 ms 14416 KB Output is correct
36 Correct 11 ms 14544 KB Output is correct
37 Correct 9 ms 14544 KB Output is correct
38 Correct 9 ms 14544 KB Output is correct
39 Correct 9 ms 14416 KB Output is correct
40 Correct 9 ms 14480 KB Output is correct
41 Correct 8 ms 14416 KB Output is correct
42 Correct 8 ms 14416 KB Output is correct
43 Execution timed out 3052 ms 19448 KB Time limit exceeded
44 Halted 0 ms 0 KB -