Submission #763745

# Submission time Handle Problem Language Result Execution time Memory
763745 2023-06-22T18:25:43 Z raysh07 Digital Circuit (IOI22_circuit) C++17
2 / 100
3000 ms 7900 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 2e5 + 69;
const int mod = 1e9 + 2022;
vector <int> adj[N];
int n, m;
int w1[N], tot[N], ok[N];

int power(int x, int y){
    if (y==0) return 1;
    
    int v = power(x, y/2);
    v *= v; v %= mod;
    
    if (y & 1) return v * x % mod;
    else return v;
}

void dfs(int u){
    int cnt = 0;
    for (int v : adj[u]){
        dfs(v);
        cnt++;
    }
    
    if (u >= n) return;
    
    int curr = 1;
    w1[u] = 0;
    
    for (int v : adj[u]){
        ok[v] = curr;
        curr *= tot[v]; 
        curr %= mod;
    }
    tot[u] = curr * cnt % mod;
    curr = 1;
    
    for (int i = adj[u].size() - 1; i >= 0; i--){
        int v = adj[u][i];
        ok[v] *= curr;
        ok[v] %= mod;
        curr *= tot[v];
        curr %= mod;
    }
    
    for (int v : adj[u]){
        w1[u] += w1[v] * ok[v] % mod;
    }
}

void init(int32_t N, int32_t M, vector<int32_t> p, vector<int32_t> a) {
    n = N;
    m = M;
    for (int i = 1; i < n + m; i++){
        adj[p[i]].push_back(i);
    }
    
    for (int i = 0; i < m; i++){
        if (a[i] == 1)
        w1[i + n] = 1;
        tot[i + n] = 1;
    }
}

int32_t count_ways(int32_t l, int32_t r) {
    for (int i = l; i <= r; i++){
        w1[i] ^= 1;
    }
    
    dfs(0);
    
    return (int32_t) w1[0];
}

// int32_t main(){
//     int32_t n, m; cin >> n >> m;
    
//     vector <int32_t> p(n + m), a(m);
//     for (auto &x : p) cin >> x;
//     for (auto &x : a) cin >> x;
//     init(n, m, p, a);
    
//     int q; cin >> q;
//     while(q--){
//         int32_t l, r;
//         cin >> l >> r;
//         cout << count_ways(l, r) << "\n";
//     }
//     return 0;
// }
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 4996 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '1052132962'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 4996 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '1052132962'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3018 ms 7900 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3018 ms 7900 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '1052132962'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 4996 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '1052132962'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 4996 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '1052132962'
11 Halted 0 ms 0 KB -