Submission #812187

# Submission time Handle Problem Language Result Execution time Memory
812187 2023-08-07T07:43:49 Z andrei_boaca Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 10932 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;
    if(muchii[nod].size()==0)
    {
        dp[a[nod]][nod]=1;
        dp[1-a[nod]][nod]=0;
        return;
    }
    for(int i:muchii[nod])
        build(i);
    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) {
  for(int i=L;i<=R;i++)
    a[i]^=1;
  build(0);
  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:61:18: 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<P.size();i++)
      |                 ~^~~~~~~~~
circuit.cpp:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i=0;i<A.size();i++)
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7376 KB Output is correct
2 Correct 3 ms 7376 KB Output is correct
3 Correct 18 ms 7464 KB Output is correct
4 Correct 19 ms 7376 KB Output is correct
5 Correct 19 ms 7392 KB Output is correct
6 Correct 19 ms 7364 KB Output is correct
7 Correct 19 ms 7376 KB Output is correct
8 Correct 19 ms 7376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7376 KB Output is correct
2 Correct 4 ms 7324 KB Output is correct
3 Correct 6 ms 7376 KB Output is correct
4 Correct 4 ms 7376 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 5 ms 7376 KB Output is correct
7 Correct 4 ms 7376 KB Output is correct
8 Correct 5 ms 7376 KB Output is correct
9 Correct 4 ms 7376 KB Output is correct
10 Correct 5 ms 7504 KB Output is correct
11 Correct 4 ms 7504 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7376 KB Output is correct
2 Correct 3 ms 7376 KB Output is correct
3 Correct 18 ms 7464 KB Output is correct
4 Correct 19 ms 7376 KB Output is correct
5 Correct 19 ms 7392 KB Output is correct
6 Correct 19 ms 7364 KB Output is correct
7 Correct 19 ms 7376 KB Output is correct
8 Correct 19 ms 7376 KB Output is correct
9 Correct 5 ms 7376 KB Output is correct
10 Correct 4 ms 7324 KB Output is correct
11 Correct 6 ms 7376 KB Output is correct
12 Correct 4 ms 7376 KB Output is correct
13 Correct 4 ms 7376 KB Output is correct
14 Correct 5 ms 7376 KB Output is correct
15 Correct 4 ms 7376 KB Output is correct
16 Correct 5 ms 7376 KB Output is correct
17 Correct 4 ms 7376 KB Output is correct
18 Correct 5 ms 7504 KB Output is correct
19 Correct 4 ms 7504 KB Output is correct
20 Correct 5 ms 7424 KB Output is correct
21 Correct 4 ms 7364 KB Output is correct
22 Correct 4 ms 7376 KB Output is correct
23 Correct 4 ms 7376 KB Output is correct
24 Correct 5 ms 7376 KB Output is correct
25 Correct 4 ms 7504 KB Output is correct
26 Correct 4 ms 7504 KB Output is correct
27 Correct 4 ms 7376 KB Output is correct
28 Correct 4 ms 7504 KB Output is correct
29 Correct 19 ms 7376 KB Output is correct
30 Correct 19 ms 7376 KB Output is correct
31 Correct 3 ms 7376 KB Output is correct
32 Correct 4 ms 7504 KB Output is correct
33 Correct 4 ms 7376 KB Output is correct
34 Correct 5 ms 7376 KB Output is correct
35 Correct 10 ms 7376 KB Output is correct
36 Correct 4 ms 7504 KB Output is correct
37 Correct 20 ms 7504 KB Output is correct
38 Correct 22 ms 7524 KB Output is correct
39 Correct 4 ms 7376 KB Output is correct
40 Correct 4 ms 7376 KB Output is correct
41 Correct 4 ms 7376 KB Output is correct
42 Correct 4 ms 7376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3091 ms 10932 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3091 ms 10932 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7376 KB Output is correct
2 Correct 4 ms 7324 KB Output is correct
3 Correct 6 ms 7376 KB Output is correct
4 Correct 4 ms 7376 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 5 ms 7376 KB Output is correct
7 Correct 4 ms 7376 KB Output is correct
8 Correct 5 ms 7376 KB Output is correct
9 Correct 4 ms 7376 KB Output is correct
10 Correct 5 ms 7504 KB Output is correct
11 Correct 4 ms 7504 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
13 Execution timed out 3091 ms 10932 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7376 KB Output is correct
2 Correct 3 ms 7376 KB Output is correct
3 Correct 18 ms 7464 KB Output is correct
4 Correct 19 ms 7376 KB Output is correct
5 Correct 19 ms 7392 KB Output is correct
6 Correct 19 ms 7364 KB Output is correct
7 Correct 19 ms 7376 KB Output is correct
8 Correct 19 ms 7376 KB Output is correct
9 Correct 5 ms 7376 KB Output is correct
10 Correct 4 ms 7324 KB Output is correct
11 Correct 6 ms 7376 KB Output is correct
12 Correct 4 ms 7376 KB Output is correct
13 Correct 4 ms 7376 KB Output is correct
14 Correct 5 ms 7376 KB Output is correct
15 Correct 4 ms 7376 KB Output is correct
16 Correct 5 ms 7376 KB Output is correct
17 Correct 4 ms 7376 KB Output is correct
18 Correct 5 ms 7504 KB Output is correct
19 Correct 4 ms 7504 KB Output is correct
20 Correct 5 ms 7424 KB Output is correct
21 Correct 4 ms 7364 KB Output is correct
22 Correct 4 ms 7376 KB Output is correct
23 Correct 4 ms 7376 KB Output is correct
24 Correct 5 ms 7376 KB Output is correct
25 Correct 4 ms 7504 KB Output is correct
26 Correct 4 ms 7504 KB Output is correct
27 Correct 4 ms 7376 KB Output is correct
28 Correct 4 ms 7504 KB Output is correct
29 Correct 19 ms 7376 KB Output is correct
30 Correct 19 ms 7376 KB Output is correct
31 Correct 3 ms 7376 KB Output is correct
32 Correct 4 ms 7504 KB Output is correct
33 Correct 4 ms 7376 KB Output is correct
34 Correct 5 ms 7376 KB Output is correct
35 Correct 10 ms 7376 KB Output is correct
36 Correct 4 ms 7504 KB Output is correct
37 Correct 20 ms 7504 KB Output is correct
38 Correct 22 ms 7524 KB Output is correct
39 Correct 4 ms 7376 KB Output is correct
40 Correct 4 ms 7376 KB Output is correct
41 Correct 4 ms 7376 KB Output is correct
42 Correct 4 ms 7376 KB Output is correct
43 Execution timed out 3015 ms 7608 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7376 KB Output is correct
2 Correct 3 ms 7376 KB Output is correct
3 Correct 18 ms 7464 KB Output is correct
4 Correct 19 ms 7376 KB Output is correct
5 Correct 19 ms 7392 KB Output is correct
6 Correct 19 ms 7364 KB Output is correct
7 Correct 19 ms 7376 KB Output is correct
8 Correct 19 ms 7376 KB Output is correct
9 Correct 5 ms 7376 KB Output is correct
10 Correct 4 ms 7324 KB Output is correct
11 Correct 6 ms 7376 KB Output is correct
12 Correct 4 ms 7376 KB Output is correct
13 Correct 4 ms 7376 KB Output is correct
14 Correct 5 ms 7376 KB Output is correct
15 Correct 4 ms 7376 KB Output is correct
16 Correct 5 ms 7376 KB Output is correct
17 Correct 4 ms 7376 KB Output is correct
18 Correct 5 ms 7504 KB Output is correct
19 Correct 4 ms 7504 KB Output is correct
20 Correct 5 ms 7424 KB Output is correct
21 Correct 4 ms 7364 KB Output is correct
22 Correct 4 ms 7376 KB Output is correct
23 Correct 4 ms 7376 KB Output is correct
24 Correct 5 ms 7376 KB Output is correct
25 Correct 4 ms 7504 KB Output is correct
26 Correct 4 ms 7504 KB Output is correct
27 Correct 4 ms 7376 KB Output is correct
28 Correct 4 ms 7504 KB Output is correct
29 Correct 19 ms 7376 KB Output is correct
30 Correct 19 ms 7376 KB Output is correct
31 Correct 3 ms 7376 KB Output is correct
32 Correct 4 ms 7504 KB Output is correct
33 Correct 4 ms 7376 KB Output is correct
34 Correct 5 ms 7376 KB Output is correct
35 Correct 10 ms 7376 KB Output is correct
36 Correct 4 ms 7504 KB Output is correct
37 Correct 20 ms 7504 KB Output is correct
38 Correct 22 ms 7524 KB Output is correct
39 Correct 4 ms 7376 KB Output is correct
40 Correct 4 ms 7376 KB Output is correct
41 Correct 4 ms 7376 KB Output is correct
42 Correct 4 ms 7376 KB Output is correct
43 Execution timed out 3091 ms 10932 KB Time limit exceeded
44 Halted 0 ms 0 KB -