답안 #927923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927923 2024-02-15T14:06:29 Z knon0501 디지털 회로 (IOI22_circuit) C++17
0 / 100
23 ms 4696 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;
        
    }
    if((dp[v][0]+dp[v][1])%D!=s[v])exit(-1);
   // 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) {

    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=1 ; i<=ch[v].size() ; i++){
      |                   ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 4696 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 4696 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 4696 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 1584 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 1584 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 4696 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 4696 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 4696 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -