Submission #788974

# Submission time Handle Problem Language Result Execution time Memory
788974 2023-07-20T18:55:48 Z mosiashvililuka Digital Circuit (IOI22_circuit) C++17
2 / 100
3000 ms 9108 KB
#include<bits/stdc++.h>
#include "circuit.h"
using namespace std;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,mod=1000002022LL,dp[200009],ALL[200009],f[200009],L,R,pr[200009],sf[200009],pas,N;
vector <long long> v[200009];
void dfs(int q, int w){
    if(v[q].size()==0){
        ALL[q]=1;
        return;
    }
    ALL[q]=v[q].size();
    for(vector <long long>::iterator it=v[q].begin(); it!=v[q].end(); it++){
        dfs((*it),q);
        ALL[q]*=ALL[(*it)];ALL[q]%=mod;
    }

    long long qw=1;
    for(vector <long long>::iterator it=v[q].begin(); it!=v[q].end(); it++){
        pr[(*it)]=qw;
        qw*=ALL[(*it)];qw%=mod;
    }
    vector <long long>::iterator it=v[q].end();it--;
    qw=1;
    for( ; ; ){
        sf[(*it)]=qw;
        qw*=ALL[(*it)];qw%=mod;
        if(it==v[q].begin()) break;
        it--;
    }

}
void dfs2(int q, int w){
    dp[q]=dp[w];
    dp[q]*=pr[q];dp[q]%=mod;
    dp[q]*=sf[q];dp[q]%=mod;
    for(vector <long long>::iterator it=v[q].begin(); it!=v[q].end(); it++){
        dfs2((*it),q);
    }
}
void init(int NN, int MM, std::vector<int> P, std::vector<int> A) {
    a=NN+MM;N=NN;
    for(ii=1; ii<P.size(); ii++){
        i=ii+1;
        v[P[ii]+1].push_back(i);
    }

    for(i=N+1; i<=a; i++){
        f[i]=A[i-N-1];
    }
    dfs(1,0);
    pr[1]=sf[1]=1;
    dp[0]=1;
    dfs2(1,0);

    /*for(i=1; i<=a; i++){
        cout<<dp[i]<<" "<<pr[i]<<" "<<sf[i]<<"\n";
    }*/
}
int count_ways(int LL, int RR) {
    L=LL+1;R=RR+1;
    for(i=L; i<=R; i++) f[i]^=1;
    pas=0;
    for(i=N+1; i<=a; i++){
        if(f[i]==1){
            pas+=dp[i];
        }
    }
    return pas;
}

Compilation message

circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:42:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(ii=1; ii<P.size(); ii++){
      |               ~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4960 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4944 KB Output is correct
2 Incorrect 2 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4960 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 4 ms 4944 KB Output is correct
10 Incorrect 2 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3090 ms 9108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3090 ms 9108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4944 KB Output is correct
2 Incorrect 2 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4960 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 4 ms 4944 KB Output is correct
10 Incorrect 2 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4960 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 4 ms 4944 KB Output is correct
10 Incorrect 2 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -