Submission #839136

# Submission time Handle Problem Language Result Execution time Memory
839136 2023-08-28T19:42:31 Z jasmin Digital Circuit (IOI22_circuit) C++17
0 / 100
16 ms 10040 KB
#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;

const int MOD=1e9+2022;
const int INF = LONG_MAX;

vector<vector<int> > adi;
vector<int> par;
vector<int> state;

vector<vector<int> > pos;

void update_node(int v){

    int s=adi[v].size()+1;
    vector<int> cnt(s);
    cnt[0] = 1;

    for(auto u: adi[v]){

        for(int i=s-1; i>=0; i--){

            cnt[i] = (cnt[i]*pos[u][0])%MOD;

            if(0<i){
                cnt[i] += (cnt[i-1]*pos[u][1])%MOD;
                cnt[i]%=MOD;
            }
        }
    }

    int ssum=0;
    pos[v][1]=0;
    for(int i=s-1; i>=1; i--){
        ssum += cnt[i];
        ssum%=MOD;

        pos[v][1] += ssum;
        pos[v][1] %= MOD;
    }

    ssum=cnt[0];
    for(int i=1; i<s; i++){

        pos[v][0] += ssum;
        pos[v][0] %= MOD;

        ssum += cnt[i];
        ssum %= MOD;
    }
}

void init(int n, int m, vector<int> p, vector<int> a) {

    par = p;
    state = a;

    adi.assign(n, {});
    for(int i=1; i<n+m; i++){

        adi[p[i]].push_back(i);
    }


    pos.assign(n, vector<int> (2, 0));
    for(int i=n; i<n+m; i++){

        pos[i][state[i]] = 1;
    }
    for(int i=n-1; i>=0; i--){
        update_node(i);
    }
}

int count_ways(int L, int R) {
    
    priority_queue<int> pq;
    for(int i=L; i<=R; i++){

        state[i] = 1-state[i];

        pos[i][state[i]] = 1;
        pos[i][1-state[i]] = 0;

        pq.push(par[i]);
    }

    set<int> done;
    while(!pq.empty()){
        int v=pq.top();
        pq.pop();

        if(done.find(v)!=done.end()) continue;
        done.insert(v);

        update_node(v);

        if(par[v]!=-1){
            pq.push(par[v]);
        }
    }

    return pos[0][1];
}

Compilation message

circuit.cpp:6:17: warning: overflow in conversion from 'long int' to 'int' changes value from '9223372036854775807' to '-1' [-Woverflow]
    6 | const int INF = LONG_MAX;
      |                 ^~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 10040 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 10040 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -