Submission #835470

# Submission time Handle Problem Language Result Execution time Memory
835470 2023-08-23T14:54:06 Z gagik_2007 Digital Circuit (IOI22_circuit) C++17
22 / 100
3000 ms 12800 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;

#define ff first
#define ss second

ll ttt;
const ll INF=1e18;
const ll MOD=1e9+2022;
const ll N=200007;
ll n,m,k;
vector<ll>g[N];
vector<ll>p;
vector<ll>a;
ll tot[N];
ll dp[N];

void calc_tot(ll v){
    if(!g[v].size()){tot[v]=1;return;}
    tot[v]=g[v].size();
    for(ll to:g[v]){
        calc_tot(to);
        tot[v]*=tot[to];
        tot[v]%=MOD;
    }
}

void calc_dp(ll v){
    if(!g[v].size()){
        dp[v]=a[v];
        return;
    }
    for(ll to:g[v])calc_dp(to);
    vector<ll>d;
    ll cur=1;
    for(ll to:g[v]){
        d.push_back(cur);
        cur*=tot[to];
        cur%=MOD;
    }
    cur=1;
    ll sum=0;
    // cout<<"DDDDD\n";
    for(ll i=g[v].size()-1;i>=0;i--){
        // cout<<g[v][i]<<": "<<d[i]<<" ";
        d[i]*=cur;
        d[i]%=MOD;
        // cout<<d[i]<<" ";
        d[i]*=dp[g[v][i]];
        d[i]%=MOD;
        // cout<<d[i]<<endl;
        sum+=d[i];
        sum%=MOD;
        cur*=tot[g[v][i]];
        cur%=MOD;
    }
    dp[v]=sum;
}

void just_calc_dp(ll v){
    if(!g[v].size()){
        dp[v]=a[v];
        return;
    }
    // for(ll to:g[v])calc_dp(to);
    vector<ll>d;
    ll cur=1;
    for(ll to:g[v]){
        d.push_back(cur);
        cur*=tot[to];
        cur%=MOD;
    }
    cur=1;
    ll sum=0;
    // cout<<"DDDDD\n";
    for(ll i=g[v].size()-1;i>=0;i--){
        // cout<<g[v][i]<<": "<<d[i]<<" ";
        d[i]*=cur;
        d[i]%=MOD;
        // cout<<d[i]<<" ";
        d[i]*=dp[g[v][i]];
        d[i]%=MOD;
        // cout<<d[i]<<endl;
        sum+=d[i];
        sum%=MOD;
        cur*=tot[g[v][i]];
        cur%=MOD;
    }
    dp[v]=sum;
}

void go_up(int v){
    just_calc_dp(v);
    while(v!=0){
        v=p[v];
        just_calc_dp(v);
    }
}

void init(int NN, int MM, vector<int> P, vector<int> A) {
    n=NN;
    m=MM;
    for(ll v=1;v<n+m;v++){
        g[P[v]].push_back(v);
        // g[v].push_back(P[v]);
    }
    for(int x:P)p.push_back(x);
    a.resize(n+m,0);
    for(ll i=0;i<m;i++){
        a[i+n]=A[i];
    }
    calc_tot(0);
    calc_dp(0);
    // for(ll v=0;v<n+m;v++){
    //     cout<<v<<": "<<tot[v]<<endl;
    // }
}

int count_ways(int L, int R) {
    for(ll i=L;i<=R;i++){
        a[i]=!a[i];
        go_up(i);
    }
    // calc_dp(0);
    // for(ll v=0;v<n+m;v++){
    //     cout<<v<<": "<<dp[v]<<", "<<a[v]<<endl;
    // }
    return dp[0];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 17 ms 5072 KB Output is correct
4 Correct 19 ms 5072 KB Output is correct
5 Correct 14 ms 5072 KB Output is correct
6 Correct 19 ms 4944 KB Output is correct
7 Correct 58 ms 5176 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 4980 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 5 ms 5072 KB Output is correct
10 Correct 86 ms 5252 KB Output is correct
11 Correct 138 ms 5240 KB Output is correct
12 Correct 3 ms 5000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 17 ms 5072 KB Output is correct
4 Correct 19 ms 5072 KB Output is correct
5 Correct 14 ms 5072 KB Output is correct
6 Correct 19 ms 4944 KB Output is correct
7 Correct 58 ms 5176 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 4 ms 4980 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 5 ms 5072 KB Output is correct
18 Correct 86 ms 5252 KB Output is correct
19 Correct 138 ms 5240 KB Output is correct
20 Correct 3 ms 5000 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 5 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 7 ms 5140 KB Output is correct
29 Correct 57 ms 4944 KB Output is correct
30 Correct 25 ms 5072 KB Output is correct
31 Correct 4 ms 5072 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 5 ms 5104 KB Output is correct
34 Correct 4 ms 5072 KB Output is correct
35 Correct 12 ms 4944 KB Output is correct
36 Correct 46 ms 5260 KB Output is correct
37 Correct 53 ms 5200 KB Output is correct
38 Correct 190 ms 5160 KB Output is correct
39 Correct 7 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 4 ms 5072 KB Output is correct
42 Correct 7 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 555 ms 8904 KB Output is correct
2 Correct 921 ms 12800 KB Output is correct
3 Correct 821 ms 12740 KB Output is correct
4 Correct 943 ms 12744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 555 ms 8904 KB Output is correct
2 Correct 921 ms 12800 KB Output is correct
3 Correct 821 ms 12740 KB Output is correct
4 Correct 943 ms 12744 KB Output is correct
5 Execution timed out 3097 ms 8976 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 4980 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 5 ms 5072 KB Output is correct
10 Correct 86 ms 5252 KB Output is correct
11 Correct 138 ms 5240 KB Output is correct
12 Correct 3 ms 5000 KB Output is correct
13 Correct 555 ms 8904 KB Output is correct
14 Correct 921 ms 12800 KB Output is correct
15 Correct 821 ms 12740 KB Output is correct
16 Correct 943 ms 12744 KB Output is correct
17 Execution timed out 3097 ms 8976 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 17 ms 5072 KB Output is correct
4 Correct 19 ms 5072 KB Output is correct
5 Correct 14 ms 5072 KB Output is correct
6 Correct 19 ms 4944 KB Output is correct
7 Correct 58 ms 5176 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 4 ms 4980 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 5 ms 5072 KB Output is correct
18 Correct 86 ms 5252 KB Output is correct
19 Correct 138 ms 5240 KB Output is correct
20 Correct 3 ms 5000 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 5 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 7 ms 5140 KB Output is correct
29 Correct 57 ms 4944 KB Output is correct
30 Correct 25 ms 5072 KB Output is correct
31 Correct 4 ms 5072 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 5 ms 5104 KB Output is correct
34 Correct 4 ms 5072 KB Output is correct
35 Correct 12 ms 4944 KB Output is correct
36 Correct 46 ms 5260 KB Output is correct
37 Correct 53 ms 5200 KB Output is correct
38 Correct 190 ms 5160 KB Output is correct
39 Correct 7 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 4 ms 5072 KB Output is correct
42 Correct 7 ms 4956 KB Output is correct
43 Execution timed out 3062 ms 5328 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 17 ms 5072 KB Output is correct
4 Correct 19 ms 5072 KB Output is correct
5 Correct 14 ms 5072 KB Output is correct
6 Correct 19 ms 4944 KB Output is correct
7 Correct 58 ms 5176 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 4 ms 4980 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 5 ms 5072 KB Output is correct
18 Correct 86 ms 5252 KB Output is correct
19 Correct 138 ms 5240 KB Output is correct
20 Correct 3 ms 5000 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 5 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 7 ms 5140 KB Output is correct
29 Correct 57 ms 4944 KB Output is correct
30 Correct 25 ms 5072 KB Output is correct
31 Correct 4 ms 5072 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 5 ms 5104 KB Output is correct
34 Correct 4 ms 5072 KB Output is correct
35 Correct 12 ms 4944 KB Output is correct
36 Correct 46 ms 5260 KB Output is correct
37 Correct 53 ms 5200 KB Output is correct
38 Correct 190 ms 5160 KB Output is correct
39 Correct 7 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 4 ms 5072 KB Output is correct
42 Correct 7 ms 4956 KB Output is correct
43 Correct 555 ms 8904 KB Output is correct
44 Correct 921 ms 12800 KB Output is correct
45 Correct 821 ms 12740 KB Output is correct
46 Correct 943 ms 12744 KB Output is correct
47 Execution timed out 3097 ms 8976 KB Time limit exceeded
48 Halted 0 ms 0 KB -