Submission #912646

# Submission time Handle Problem Language Result Execution time Memory
912646 2024-01-19T17:14:26 Z biank Digital Circuit (IOI22_circuit) C++17
0 / 100
13 ms 2548 KB
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define ALL(x) x.begin(),x.end()
#define SIZE(x) (int)x.size()
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define dforsn(i,s,n) for(int i=int(n)-1;i>=int(s);i--)
#define dforn(i,n) for(int i=int(n)-1;i>=0;i--)
#define fst first
#define snd second
#define pb push_back
const int MAXN = 2000;
const int MOD = 1e9+2022;
vi s, adj[MAXN];
int n, m;

void init(int N, int M, vi P, vi A) {
    s=A, n=N, m=M;
    forsn(i,1,n+m) adj[P[i]].pb(i);
}

int mul(int x, int y) {
    return (long long) x * y % MOD;
}

void add(int &x, int v) {
    x+=v;
    if(x>=MOD) x-=MOD;
}

ii dfs(int u) {
    int c=SIZE(adj[u]);
    if(!c) return {!s[u-n], s[u-n]};
    vi ways(c+1,0);
    ways[0] = 1;
    forn(i,c) {
        ii child=dfs(adj[u][i]);
        dforn(j,i+1) {
            ways[j] = mul(ways[j],child.fst);
            if(j) add(ways[j],mul(ways[j-1],child.snd));
        }
    }
    ii ans = {0,0};
    forsn(i,1,c+1) {
        forn(j,i) add(ans.fst, ways[j]);
        forsn(j,i,c+1) add(ans.snd, ways[j]);
    }
    return ans;
}

int count_ways(int L, int R) {
    forsn(i,L,R+1) {
        s[i-n]^=1;
    }
    return int(dfs(0).snd);
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 2548 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 2548 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -