답안 #812204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
812204 2023-08-07T07:49:04 Z andrei_boaca 디지털 회로 (IOI22_circuit) C++17
34 / 100
3000 ms 21612 KB
#include "circuit.h"
#include <bits/stdc++.h>
#include <vector>
//#include "stub.cpp"

using namespace std;
typedef long long ll;
const ll mod=1e9+2022;
ll a[300005],par[300005];
ll n,m,minim[300005],maxim[300005],dp[2][300005],toprop[300005];
vector<ll> muchii[300005];
ll nr[300005],aux[300005];
void calc(int nod)
{
    dp[1][nod]=dp[0][nod]=0;
    for(int j=0;j<=muchii[nod].size();j++)
        nr[j]=0;
    nr[0]=1;
    for(int i=0;i<muchii[nod].size();i++)
    {
        for(int j=0;j<=i+1;j++)
            aux[j]=0;
        for(int j=0;j<=i+1;j++)
        {
            ll val=(nr[j]*dp[0][muchii[nod][i]])%mod;
            aux[j]=(aux[j]+val)%mod;
            if(j>0)
            {
                val=(nr[j-1]*dp[1][muchii[nod][i]])%mod;
                aux[j]=(aux[j]+val)%mod;
            }
        }
        for(int j=0;j<=i+1;j++)
            nr[j]=aux[j];
    }
    for(ll i=0;i<=muchii[nod].size();i++)
    {
        ll nr1=(nr[i]*i)%mod;
        dp[1][nod]=(dp[1][nod]+nr1)%mod;
        ll nr0=(1LL*nr[i]*(muchii[nod].size()-i))%mod;
        dp[0][nod]=(dp[0][nod]+nr0)%mod;
    }
}
void build(int nod)
{
    dp[1][nod]=dp[0][nod]=0;
    minim[nod]=1e9;
    maxim[nod]=-1;
    if(muchii[nod].size()==0)
    {
        dp[a[nod]][nod]=1;
        dp[1-a[nod]][nod]=0;
        minim[nod]=nod;
        maxim[nod]=nod;
        return;
    }
    for(int i:muchii[nod])
    {
        build(i);
        minim[nod]=min(minim[nod],minim[i]);
        maxim[nod]=max(maxim[nod],maxim[i]);
    }
    calc(nod);
}
void prop(int nod)
{
    for(int i:muchii[nod])
    {
        swap(dp[0][i],dp[1][i]);
        toprop[i]^=1;
    }
}
void update(int nod,int l,int r)
{
    if(muchii[nod].size()>0&&toprop[nod])
    {
        prop(nod);
        toprop[nod]=0;
    }
    if(l<=minim[nod]&&r>=maxim[nod])
    {
        swap(dp[0][nod],dp[1][nod]);
        toprop[nod]^=1;
        return;
    }
    for(int i:muchii[nod])
    {
        if(!(maxim[i]<l||minim[i]>r))
            update(i,l,r);
    }
    calc(nod);
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n=N;
    m=M;
    for(int i=0;i<P.size();i++)
    {
        par[i]=P[i];
        if(i!=0)
            muchii[par[i]].push_back(i);
    }
    for(int i=0;i<A.size();i++)
        a[i+n]=A[i];
    build(0);
}

int count_ways(int L, int R) {
    update(0,L,R);
    return dp[1][0];
}


Compilation message

circuit.cpp: In function 'void calc(int)':
circuit.cpp:16:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int j=0;j<=muchii[nod].size();j++)
      |                 ~^~~~~~~~~~~~~~~~~~~~
circuit.cpp:19:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i=0;i<muchii[nod].size();i++)
      |                 ~^~~~~~~~~~~~~~~~~~~
circuit.cpp:36:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(ll i=0;i<=muchii[nod].size();i++)
      |                ~^~~~~~~~~~~~~~~~~~~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:96:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     for(int i=0;i<P.size();i++)
      |                 ~^~~~~~~~~
circuit.cpp:102:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |     for(int i=0;i<A.size();i++)
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7300 KB Output is correct
2 Correct 3 ms 7376 KB Output is correct
3 Correct 18 ms 7500 KB Output is correct
4 Correct 19 ms 7504 KB Output is correct
5 Correct 19 ms 7504 KB Output is correct
6 Correct 19 ms 7504 KB Output is correct
7 Correct 19 ms 7508 KB Output is correct
8 Correct 19 ms 7504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7376 KB Output is correct
2 Correct 3 ms 7388 KB Output is correct
3 Correct 3 ms 7376 KB Output is correct
4 Correct 5 ms 7376 KB Output is correct
5 Correct 4 ms 7424 KB Output is correct
6 Correct 4 ms 7504 KB Output is correct
7 Correct 4 ms 7504 KB Output is correct
8 Correct 4 ms 7504 KB Output is correct
9 Correct 4 ms 7504 KB Output is correct
10 Correct 4 ms 7632 KB Output is correct
11 Correct 4 ms 7624 KB Output is correct
12 Correct 4 ms 7504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7300 KB Output is correct
2 Correct 3 ms 7376 KB Output is correct
3 Correct 18 ms 7500 KB Output is correct
4 Correct 19 ms 7504 KB Output is correct
5 Correct 19 ms 7504 KB Output is correct
6 Correct 19 ms 7504 KB Output is correct
7 Correct 19 ms 7508 KB Output is correct
8 Correct 19 ms 7504 KB Output is correct
9 Correct 4 ms 7376 KB Output is correct
10 Correct 3 ms 7388 KB Output is correct
11 Correct 3 ms 7376 KB Output is correct
12 Correct 5 ms 7376 KB Output is correct
13 Correct 4 ms 7424 KB Output is correct
14 Correct 4 ms 7504 KB Output is correct
15 Correct 4 ms 7504 KB Output is correct
16 Correct 4 ms 7504 KB Output is correct
17 Correct 4 ms 7504 KB Output is correct
18 Correct 4 ms 7632 KB Output is correct
19 Correct 4 ms 7624 KB Output is correct
20 Correct 4 ms 7504 KB Output is correct
21 Correct 4 ms 7476 KB Output is correct
22 Correct 4 ms 7504 KB Output is correct
23 Correct 4 ms 7504 KB Output is correct
24 Correct 4 ms 7456 KB Output is correct
25 Correct 4 ms 7504 KB Output is correct
26 Correct 4 ms 7500 KB Output is correct
27 Correct 4 ms 7556 KB Output is correct
28 Correct 3 ms 7504 KB Output is correct
29 Correct 20 ms 7512 KB Output is correct
30 Correct 20 ms 7504 KB Output is correct
31 Correct 4 ms 7504 KB Output is correct
32 Correct 4 ms 7488 KB Output is correct
33 Correct 4 ms 7504 KB Output is correct
34 Correct 4 ms 7504 KB Output is correct
35 Correct 6 ms 7436 KB Output is correct
36 Correct 4 ms 7504 KB Output is correct
37 Correct 21 ms 7632 KB Output is correct
38 Correct 20 ms 7656 KB Output is correct
39 Correct 4 ms 7508 KB Output is correct
40 Correct 4 ms 7504 KB Output is correct
41 Correct 4 ms 7504 KB Output is correct
42 Correct 4 ms 7376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 563 ms 11980 KB Output is correct
2 Correct 965 ms 16540 KB Output is correct
3 Correct 945 ms 16568 KB Output is correct
4 Correct 906 ms 16624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 563 ms 11980 KB Output is correct
2 Correct 965 ms 16540 KB Output is correct
3 Correct 945 ms 16568 KB Output is correct
4 Correct 906 ms 16624 KB Output is correct
5 Correct 797 ms 12168 KB Output is correct
6 Correct 1069 ms 16908 KB Output is correct
7 Correct 989 ms 16900 KB Output is correct
8 Correct 862 ms 16584 KB Output is correct
9 Correct 384 ms 7608 KB Output is correct
10 Correct 882 ms 8000 KB Output is correct
11 Correct 859 ms 8016 KB Output is correct
12 Correct 854 ms 8016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7376 KB Output is correct
2 Correct 3 ms 7388 KB Output is correct
3 Correct 3 ms 7376 KB Output is correct
4 Correct 5 ms 7376 KB Output is correct
5 Correct 4 ms 7424 KB Output is correct
6 Correct 4 ms 7504 KB Output is correct
7 Correct 4 ms 7504 KB Output is correct
8 Correct 4 ms 7504 KB Output is correct
9 Correct 4 ms 7504 KB Output is correct
10 Correct 4 ms 7632 KB Output is correct
11 Correct 4 ms 7624 KB Output is correct
12 Correct 4 ms 7504 KB Output is correct
13 Correct 563 ms 11980 KB Output is correct
14 Correct 965 ms 16540 KB Output is correct
15 Correct 945 ms 16568 KB Output is correct
16 Correct 906 ms 16624 KB Output is correct
17 Correct 797 ms 12168 KB Output is correct
18 Correct 1069 ms 16908 KB Output is correct
19 Correct 989 ms 16900 KB Output is correct
20 Correct 862 ms 16584 KB Output is correct
21 Correct 384 ms 7608 KB Output is correct
22 Correct 882 ms 8000 KB Output is correct
23 Correct 859 ms 8016 KB Output is correct
24 Correct 854 ms 8016 KB Output is correct
25 Execution timed out 3043 ms 21612 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7300 KB Output is correct
2 Correct 3 ms 7376 KB Output is correct
3 Correct 18 ms 7500 KB Output is correct
4 Correct 19 ms 7504 KB Output is correct
5 Correct 19 ms 7504 KB Output is correct
6 Correct 19 ms 7504 KB Output is correct
7 Correct 19 ms 7508 KB Output is correct
8 Correct 19 ms 7504 KB Output is correct
9 Correct 4 ms 7376 KB Output is correct
10 Correct 3 ms 7388 KB Output is correct
11 Correct 3 ms 7376 KB Output is correct
12 Correct 5 ms 7376 KB Output is correct
13 Correct 4 ms 7424 KB Output is correct
14 Correct 4 ms 7504 KB Output is correct
15 Correct 4 ms 7504 KB Output is correct
16 Correct 4 ms 7504 KB Output is correct
17 Correct 4 ms 7504 KB Output is correct
18 Correct 4 ms 7632 KB Output is correct
19 Correct 4 ms 7624 KB Output is correct
20 Correct 4 ms 7504 KB Output is correct
21 Correct 4 ms 7476 KB Output is correct
22 Correct 4 ms 7504 KB Output is correct
23 Correct 4 ms 7504 KB Output is correct
24 Correct 4 ms 7456 KB Output is correct
25 Correct 4 ms 7504 KB Output is correct
26 Correct 4 ms 7500 KB Output is correct
27 Correct 4 ms 7556 KB Output is correct
28 Correct 3 ms 7504 KB Output is correct
29 Correct 20 ms 7512 KB Output is correct
30 Correct 20 ms 7504 KB Output is correct
31 Correct 4 ms 7504 KB Output is correct
32 Correct 4 ms 7488 KB Output is correct
33 Correct 4 ms 7504 KB Output is correct
34 Correct 4 ms 7504 KB Output is correct
35 Correct 6 ms 7436 KB Output is correct
36 Correct 4 ms 7504 KB Output is correct
37 Correct 21 ms 7632 KB Output is correct
38 Correct 20 ms 7656 KB Output is correct
39 Correct 4 ms 7508 KB Output is correct
40 Correct 4 ms 7504 KB Output is correct
41 Correct 4 ms 7504 KB Output is correct
42 Correct 4 ms 7376 KB Output is correct
43 Execution timed out 3070 ms 7760 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7300 KB Output is correct
2 Correct 3 ms 7376 KB Output is correct
3 Correct 18 ms 7500 KB Output is correct
4 Correct 19 ms 7504 KB Output is correct
5 Correct 19 ms 7504 KB Output is correct
6 Correct 19 ms 7504 KB Output is correct
7 Correct 19 ms 7508 KB Output is correct
8 Correct 19 ms 7504 KB Output is correct
9 Correct 4 ms 7376 KB Output is correct
10 Correct 3 ms 7388 KB Output is correct
11 Correct 3 ms 7376 KB Output is correct
12 Correct 5 ms 7376 KB Output is correct
13 Correct 4 ms 7424 KB Output is correct
14 Correct 4 ms 7504 KB Output is correct
15 Correct 4 ms 7504 KB Output is correct
16 Correct 4 ms 7504 KB Output is correct
17 Correct 4 ms 7504 KB Output is correct
18 Correct 4 ms 7632 KB Output is correct
19 Correct 4 ms 7624 KB Output is correct
20 Correct 4 ms 7504 KB Output is correct
21 Correct 4 ms 7476 KB Output is correct
22 Correct 4 ms 7504 KB Output is correct
23 Correct 4 ms 7504 KB Output is correct
24 Correct 4 ms 7456 KB Output is correct
25 Correct 4 ms 7504 KB Output is correct
26 Correct 4 ms 7500 KB Output is correct
27 Correct 4 ms 7556 KB Output is correct
28 Correct 3 ms 7504 KB Output is correct
29 Correct 20 ms 7512 KB Output is correct
30 Correct 20 ms 7504 KB Output is correct
31 Correct 4 ms 7504 KB Output is correct
32 Correct 4 ms 7488 KB Output is correct
33 Correct 4 ms 7504 KB Output is correct
34 Correct 4 ms 7504 KB Output is correct
35 Correct 6 ms 7436 KB Output is correct
36 Correct 4 ms 7504 KB Output is correct
37 Correct 21 ms 7632 KB Output is correct
38 Correct 20 ms 7656 KB Output is correct
39 Correct 4 ms 7508 KB Output is correct
40 Correct 4 ms 7504 KB Output is correct
41 Correct 4 ms 7504 KB Output is correct
42 Correct 4 ms 7376 KB Output is correct
43 Correct 563 ms 11980 KB Output is correct
44 Correct 965 ms 16540 KB Output is correct
45 Correct 945 ms 16568 KB Output is correct
46 Correct 906 ms 16624 KB Output is correct
47 Correct 797 ms 12168 KB Output is correct
48 Correct 1069 ms 16908 KB Output is correct
49 Correct 989 ms 16900 KB Output is correct
50 Correct 862 ms 16584 KB Output is correct
51 Correct 384 ms 7608 KB Output is correct
52 Correct 882 ms 8000 KB Output is correct
53 Correct 859 ms 8016 KB Output is correct
54 Correct 854 ms 8016 KB Output is correct
55 Execution timed out 3043 ms 21612 KB Time limit exceeded
56 Halted 0 ms 0 KB -