Submission #927928

# Submission time Handle Problem Language Result Execution time Memory
927928 2024-02-15T14:09:08 Z knon0501 Digital Circuit (IOI22_circuit) C++17
46 / 100
2668 ms 723864 KB
#include "circuit.h"

#include <vector>
#include <bits/stdc++.h>
using namespace std;
const long long D = 1e9+2022;
const int MX = 1e4+5;
vector<int> ch[MX];
int n,m;
long long cnt[MX];
long long s[MX];
long long dp[MX][2];
long long dp2[MX][MX];
int nn;
long long seg[MX*4];
int a[MX];

long long t;

void dfs(int v){
 
    s[v]=ch[v].size();
    if(s[v]==0)s[v]=1;

    if(ch[v].size()==0){
        dp[v][a[v]]= 1;
   
    }

    for(auto u: ch[v]){
        dfs(u);
        s[v]=s[v]*s[u]%D;
    }
    dp2[v][0] = 1;
   
    for(auto u: ch[v]){
        for(int i=ch[v].size() ; i>=0 ; i--){
         
            if(i>0)
                dp2[v][i] =(dp2[v][i-1]*dp[u][1] + dp2[v][i]*dp[u][0])%D;
            else dp2[v][i] = dp2[v][i]*dp[u][0]%D;
        }
    }
    for(int i=0 ; i<=ch[v].size() ; i++){
        dp[v][1] = (dp[v][1] + dp2[v][i]*i)%D;
        dp[v][0] = (dp[v][0] + dp2[v][i]*(ch[v].size()-i))%D;
        
    }
    
   // if((dp[v][0]+dp[v][1])%D!=s[v])exit(-1);
 //  cout<<v<<" "<<dp[v][0]<<" "<<dp[v][1]<<" "<<s[v]<<endl;
}
void f(int v,long long k){
    cnt[v] = k;
    int l = ch[v].size();
    vector<long long> t(l);
    vector<long long> tt(l);
    for(int i=0 ; i<l ; i++){
        if(i==0)
            t[i] = s[ch[v][i]];
        else
            t[i] = t[i-1]* s[ch[v][i]]%D;
    }
    for(int i=l-1 ; i>= 0 ; i--){
        if(i==l-1)
            tt[i]=s[ch[v][i]];
        else
            tt[i]=tt[i+1]*s[ch[v][i]]%D;
    }

    for(int i=0 ; i<l ; i++){
        long long kk = k*(i==0 ? 1:t[i-1])%D*(i==l-1 ? 1:tt[i+1])%D;
        f(ch[v][i],kk);
    }
}
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++){
        ch[P[i]].push_back(i);
    }
    
    for(int i=0 ; i<M ; i++)
        a[N+i]=A[i];
 
    dfs(0);
 
    f(0,1);
    t = dp[0][1];
  //  cout<<t<<endl;
}   

int count_ways(int L, int R) {

    for(int i=L ; i<=R ; i++){
        if(a[i]==0)
            t=(t+cnt[i])%D;
        else
            t=(t-cnt[i]+D)%D;
        a[i]=1-a[i];
    }

    return t;
}

Compilation message

circuit.cpp: In function 'void dfs(int)':
circuit.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i=0 ; i<=ch[v].size() ; i++){
      |                   ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4696 KB Output is correct
3 Correct 11 ms 80724 KB Output is correct
4 Correct 10 ms 82776 KB Output is correct
5 Correct 10 ms 82776 KB Output is correct
6 Correct 10 ms 82792 KB Output is correct
7 Correct 10 ms 82776 KB Output is correct
8 Correct 10 ms 82776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 5 ms 43608 KB Output is correct
3 Correct 10 ms 84824 KB Output is correct
4 Correct 9 ms 84824 KB Output is correct
5 Correct 9 ms 84824 KB Output is correct
6 Correct 13 ms 117592 KB Output is correct
7 Correct 25 ms 160780 KB Output is correct
8 Correct 18 ms 160600 KB Output is correct
9 Correct 18 ms 160596 KB Output is correct
10 Correct 17 ms 160932 KB Output is correct
11 Correct 18 ms 160856 KB Output is correct
12 Correct 15 ms 136080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4696 KB Output is correct
3 Correct 11 ms 80724 KB Output is correct
4 Correct 10 ms 82776 KB Output is correct
5 Correct 10 ms 82776 KB Output is correct
6 Correct 10 ms 82792 KB Output is correct
7 Correct 10 ms 82776 KB Output is correct
8 Correct 10 ms 82776 KB Output is correct
9 Correct 1 ms 4696 KB Output is correct
10 Correct 5 ms 43608 KB Output is correct
11 Correct 10 ms 84824 KB Output is correct
12 Correct 9 ms 84824 KB Output is correct
13 Correct 9 ms 84824 KB Output is correct
14 Correct 13 ms 117592 KB Output is correct
15 Correct 25 ms 160780 KB Output is correct
16 Correct 18 ms 160600 KB Output is correct
17 Correct 18 ms 160596 KB Output is correct
18 Correct 17 ms 160932 KB Output is correct
19 Correct 18 ms 160856 KB Output is correct
20 Correct 15 ms 136080 KB Output is correct
21 Correct 21 ms 134104 KB Output is correct
22 Correct 12 ms 105304 KB Output is correct
23 Correct 10 ms 99200 KB Output is correct
24 Correct 27 ms 160600 KB Output is correct
25 Correct 18 ms 160572 KB Output is correct
26 Correct 19 ms 160600 KB Output is correct
27 Correct 20 ms 160600 KB Output is correct
28 Correct 25 ms 160592 KB Output is correct
29 Correct 10 ms 82776 KB Output is correct
30 Correct 13 ms 82776 KB Output is correct
31 Correct 8 ms 82776 KB Output is correct
32 Correct 22 ms 160596 KB Output is correct
33 Correct 13 ms 121688 KB Output is correct
34 Correct 11 ms 101208 KB Output is correct
35 Correct 8 ms 74584 KB Output is correct
36 Correct 18 ms 160856 KB Output is correct
37 Correct 20 ms 160884 KB Output is correct
38 Correct 19 ms 160856 KB Output is correct
39 Correct 10 ms 92900 KB Output is correct
40 Correct 11 ms 107352 KB Output is correct
41 Correct 11 ms 101208 KB Output is correct
42 Correct 9 ms 80728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 1592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 1592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 5 ms 43608 KB Output is correct
3 Correct 10 ms 84824 KB Output is correct
4 Correct 9 ms 84824 KB Output is correct
5 Correct 9 ms 84824 KB Output is correct
6 Correct 13 ms 117592 KB Output is correct
7 Correct 25 ms 160780 KB Output is correct
8 Correct 18 ms 160600 KB Output is correct
9 Correct 18 ms 160596 KB Output is correct
10 Correct 17 ms 160932 KB Output is correct
11 Correct 18 ms 160856 KB Output is correct
12 Correct 15 ms 136080 KB Output is correct
13 Runtime error 26 ms 1592 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4696 KB Output is correct
3 Correct 11 ms 80724 KB Output is correct
4 Correct 10 ms 82776 KB Output is correct
5 Correct 10 ms 82776 KB Output is correct
6 Correct 10 ms 82792 KB Output is correct
7 Correct 10 ms 82776 KB Output is correct
8 Correct 10 ms 82776 KB Output is correct
9 Correct 1 ms 4696 KB Output is correct
10 Correct 5 ms 43608 KB Output is correct
11 Correct 10 ms 84824 KB Output is correct
12 Correct 9 ms 84824 KB Output is correct
13 Correct 9 ms 84824 KB Output is correct
14 Correct 13 ms 117592 KB Output is correct
15 Correct 25 ms 160780 KB Output is correct
16 Correct 18 ms 160600 KB Output is correct
17 Correct 18 ms 160596 KB Output is correct
18 Correct 17 ms 160932 KB Output is correct
19 Correct 18 ms 160856 KB Output is correct
20 Correct 15 ms 136080 KB Output is correct
21 Correct 21 ms 134104 KB Output is correct
22 Correct 12 ms 105304 KB Output is correct
23 Correct 10 ms 99200 KB Output is correct
24 Correct 27 ms 160600 KB Output is correct
25 Correct 18 ms 160572 KB Output is correct
26 Correct 19 ms 160600 KB Output is correct
27 Correct 20 ms 160600 KB Output is correct
28 Correct 25 ms 160592 KB Output is correct
29 Correct 10 ms 82776 KB Output is correct
30 Correct 13 ms 82776 KB Output is correct
31 Correct 8 ms 82776 KB Output is correct
32 Correct 22 ms 160596 KB Output is correct
33 Correct 13 ms 121688 KB Output is correct
34 Correct 11 ms 101208 KB Output is correct
35 Correct 8 ms 74584 KB Output is correct
36 Correct 18 ms 160856 KB Output is correct
37 Correct 20 ms 160884 KB Output is correct
38 Correct 19 ms 160856 KB Output is correct
39 Correct 10 ms 92900 KB Output is correct
40 Correct 11 ms 107352 KB Output is correct
41 Correct 11 ms 101208 KB Output is correct
42 Correct 9 ms 80728 KB Output is correct
43 Correct 712 ms 378160 KB Output is correct
44 Correct 840 ms 387976 KB Output is correct
45 Correct 895 ms 384564 KB Output is correct
46 Correct 531 ms 400208 KB Output is correct
47 Correct 1189 ms 400208 KB Output is correct
48 Correct 1197 ms 400140 KB Output is correct
49 Correct 1200 ms 400204 KB Output is correct
50 Correct 2251 ms 400208 KB Output is correct
51 Correct 2651 ms 381344 KB Output is correct
52 Correct 1284 ms 394944 KB Output is correct
53 Correct 513 ms 395856 KB Output is correct
54 Correct 1206 ms 699260 KB Output is correct
55 Correct 1197 ms 591868 KB Output is correct
56 Correct 1153 ms 493348 KB Output is correct
57 Correct 1182 ms 388532 KB Output is correct
58 Correct 1242 ms 723656 KB Output is correct
59 Correct 1346 ms 723700 KB Output is correct
60 Correct 2668 ms 723864 KB Output is correct
61 Correct 875 ms 505936 KB Output is correct
62 Correct 949 ms 443968 KB Output is correct
63 Correct 1006 ms 417360 KB Output is correct
64 Correct 1138 ms 398928 KB Output is correct
65 Correct 418 ms 324940 KB Output is correct
66 Correct 1040 ms 645200 KB Output is correct
67 Correct 1081 ms 645200 KB Output is correct
68 Correct 2041 ms 645180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4696 KB Output is correct
3 Correct 11 ms 80724 KB Output is correct
4 Correct 10 ms 82776 KB Output is correct
5 Correct 10 ms 82776 KB Output is correct
6 Correct 10 ms 82792 KB Output is correct
7 Correct 10 ms 82776 KB Output is correct
8 Correct 10 ms 82776 KB Output is correct
9 Correct 1 ms 4696 KB Output is correct
10 Correct 5 ms 43608 KB Output is correct
11 Correct 10 ms 84824 KB Output is correct
12 Correct 9 ms 84824 KB Output is correct
13 Correct 9 ms 84824 KB Output is correct
14 Correct 13 ms 117592 KB Output is correct
15 Correct 25 ms 160780 KB Output is correct
16 Correct 18 ms 160600 KB Output is correct
17 Correct 18 ms 160596 KB Output is correct
18 Correct 17 ms 160932 KB Output is correct
19 Correct 18 ms 160856 KB Output is correct
20 Correct 15 ms 136080 KB Output is correct
21 Correct 21 ms 134104 KB Output is correct
22 Correct 12 ms 105304 KB Output is correct
23 Correct 10 ms 99200 KB Output is correct
24 Correct 27 ms 160600 KB Output is correct
25 Correct 18 ms 160572 KB Output is correct
26 Correct 19 ms 160600 KB Output is correct
27 Correct 20 ms 160600 KB Output is correct
28 Correct 25 ms 160592 KB Output is correct
29 Correct 10 ms 82776 KB Output is correct
30 Correct 13 ms 82776 KB Output is correct
31 Correct 8 ms 82776 KB Output is correct
32 Correct 22 ms 160596 KB Output is correct
33 Correct 13 ms 121688 KB Output is correct
34 Correct 11 ms 101208 KB Output is correct
35 Correct 8 ms 74584 KB Output is correct
36 Correct 18 ms 160856 KB Output is correct
37 Correct 20 ms 160884 KB Output is correct
38 Correct 19 ms 160856 KB Output is correct
39 Correct 10 ms 92900 KB Output is correct
40 Correct 11 ms 107352 KB Output is correct
41 Correct 11 ms 101208 KB Output is correct
42 Correct 9 ms 80728 KB Output is correct
43 Runtime error 26 ms 1592 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -