Submission #927906

# Submission time Handle Problem Language Result Execution time Memory
927906 2024-02-15T13:57:50 Z knon0501 Digital Circuit (IOI22_circuit) C++17
2 / 100
24 ms 82776 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=1 ; 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;
        
    }
   // cout<<v<<" "<<dp[v][0]<<" "<<dp[v][1]<<" "<<dp2[v][1]<<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) {
     int kk=0;
    for(int i=n ; i<n+m; i++)kk+=a[i];
    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];
    }
    int k=0;
    for(int i=n ; i<n+m; i++)k+=a[i];
    if(k!=0 && t==0)return cnt[R];
    return t;
}

Compilation message

circuit.cpp: In function 'void dfs(int)':
circuit.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i=1 ; 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 10 ms 80728 KB Output is correct
4 Correct 10 ms 82776 KB Output is correct
5 Correct 10 ms 82776 KB Output is correct
6 Correct 11 ms 82776 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 Incorrect 5 ms 43608 KB 1st lines differ - on the 1st token, expected: '52130940', found: '422283126'
3 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 10 ms 80728 KB Output is correct
4 Correct 10 ms 82776 KB Output is correct
5 Correct 10 ms 82776 KB Output is correct
6 Correct 11 ms 82776 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 Incorrect 5 ms 43608 KB 1st lines differ - on the 1st token, expected: '52130940', found: '422283126'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 1596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 24 ms 1596 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 Incorrect 5 ms 43608 KB 1st lines differ - on the 1st token, expected: '52130940', found: '422283126'
3 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 10 ms 80728 KB Output is correct
4 Correct 10 ms 82776 KB Output is correct
5 Correct 10 ms 82776 KB Output is correct
6 Correct 11 ms 82776 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 Incorrect 5 ms 43608 KB 1st lines differ - on the 1st token, expected: '52130940', found: '422283126'
11 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 10 ms 80728 KB Output is correct
4 Correct 10 ms 82776 KB Output is correct
5 Correct 10 ms 82776 KB Output is correct
6 Correct 11 ms 82776 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 Incorrect 5 ms 43608 KB 1st lines differ - on the 1st token, expected: '52130940', found: '422283126'
11 Halted 0 ms 0 KB -