Submission #964672

# Submission time Handle Problem Language Result Execution time Memory
964672 2024-04-17T10:15:08 Z steveonalex Digital Circuit (IOI22_circuit) C++17
18 / 100
3000 ms 8316 KB
#include <bits/stdc++.h>
#include "circuit.h"

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
 
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b){a = b; return true;}
        return false;
    }
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b){a = b; return true;}
        return false;
    }
template <class T>
    void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
        for(auto i: a) out << i << separator;
        out << finish;
    }
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 2e5 + 69, MOD = 1e9 + 2022;
int n, m;
vector<int> graph[N];
int dp[N][2];

void init(int _n, int _m, vector<int> P, vector<int> A) {
    n = _n, m = _m;
    for(int i = 1; i<n+m; ++i){
        graph[P[i]].push_back(i);
    }

    for(int i = 0; i<m; ++i){
        dp[i+n][A[i]] = 1;
    }
}   

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

void go(int u, int p){
    if (u >= n) return;
    dp[u][0] = dp[u][1] = 0;

    vector<int> f(graph[u].size() + 1);
    f[0] = 1;

    for(int v: graph[u]) if (v != p){
        go(v, u);
        for(int j = f.size() - 2; j>=0; --j){
            add(f[j+1], 1LL * f[j] * dp[v][1] % MOD);
            f[j] = 1LL * f[j] * dp[v][0] % MOD;
        }
    }

    int sum = 0;
    for(int i = f.size() - 1; i>=1; --i){
        add(sum, f[i]);
        add(dp[u][1], sum);
    }
    sum = 0;
    for(int i = 0; i<f.size() - 1; ++i){
        add(sum, f[i]);
        add(dp[u][0], sum);
    }
}

int count_ways(int l, int r) {
    for(int i = l; i <= r; ++i){
        swap(dp[i][0], dp[i][1]);
    }

    go(0, 0);


    return dp[0][1];
}


// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     int n, m; cin >> n >> m;
//     vector<int> P(n+m, -1);
//     for(int i = 1; i<n+m; ++i) cin >> P[i];
//     vector<int> A(m); 
//     for(int i = 0; i<m; ++i) cin >> A[i];

//     init(n, m, P, A);
//     int q; cin >> q;
//     while(q--){
//         int l, r; cin >> l >> r;
//         cout << count_ways(l, r) << "\n";
//     }


//     return 0;
// }

Compilation message

circuit.cpp: In function 'void go(int, int)':
circuit.cpp:89:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     for(int i = 0; i<f.size() - 1; ++i){
      |                    ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 3 ms 6488 KB Output is correct
3 Correct 16 ms 6740 KB Output is correct
4 Correct 16 ms 6488 KB Output is correct
5 Correct 16 ms 6488 KB Output is correct
6 Correct 20 ms 6488 KB Output is correct
7 Correct 17 ms 6488 KB Output is correct
8 Correct 19 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 3 ms 6488 KB Output is correct
6 Correct 2 ms 6488 KB Output is correct
7 Correct 3 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 3 ms 6488 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 3 ms 6488 KB Output is correct
3 Correct 16 ms 6740 KB Output is correct
4 Correct 16 ms 6488 KB Output is correct
5 Correct 16 ms 6488 KB Output is correct
6 Correct 20 ms 6488 KB Output is correct
7 Correct 17 ms 6488 KB Output is correct
8 Correct 19 ms 6488 KB Output is correct
9 Correct 3 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 2 ms 6488 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 3 ms 6488 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 3 ms 6488 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 2 ms 6488 KB Output is correct
18 Correct 2 ms 6488 KB Output is correct
19 Correct 3 ms 6488 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 2 ms 6488 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 2 ms 6488 KB Output is correct
24 Correct 3 ms 6488 KB Output is correct
25 Correct 2 ms 6488 KB Output is correct
26 Correct 4 ms 6488 KB Output is correct
27 Correct 2 ms 6488 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
29 Correct 16 ms 6556 KB Output is correct
30 Correct 16 ms 6488 KB Output is correct
31 Correct 3 ms 6488 KB Output is correct
32 Correct 2 ms 6488 KB Output is correct
33 Correct 3 ms 6488 KB Output is correct
34 Correct 2 ms 6488 KB Output is correct
35 Correct 5 ms 6488 KB Output is correct
36 Correct 2 ms 6488 KB Output is correct
37 Correct 17 ms 6488 KB Output is correct
38 Correct 18 ms 6488 KB Output is correct
39 Correct 2 ms 6488 KB Output is correct
40 Correct 3 ms 6488 KB Output is correct
41 Correct 3 ms 6488 KB Output is correct
42 Correct 3 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3010 ms 8316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3010 ms 8316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 2 ms 6488 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 2 ms 6488 KB Output is correct
5 Correct 3 ms 6488 KB Output is correct
6 Correct 2 ms 6488 KB Output is correct
7 Correct 3 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 3 ms 6488 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Execution timed out 3010 ms 8316 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 3 ms 6488 KB Output is correct
3 Correct 16 ms 6740 KB Output is correct
4 Correct 16 ms 6488 KB Output is correct
5 Correct 16 ms 6488 KB Output is correct
6 Correct 20 ms 6488 KB Output is correct
7 Correct 17 ms 6488 KB Output is correct
8 Correct 19 ms 6488 KB Output is correct
9 Correct 3 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 2 ms 6488 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 3 ms 6488 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 3 ms 6488 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 2 ms 6488 KB Output is correct
18 Correct 2 ms 6488 KB Output is correct
19 Correct 3 ms 6488 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 2 ms 6488 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 2 ms 6488 KB Output is correct
24 Correct 3 ms 6488 KB Output is correct
25 Correct 2 ms 6488 KB Output is correct
26 Correct 4 ms 6488 KB Output is correct
27 Correct 2 ms 6488 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
29 Correct 16 ms 6556 KB Output is correct
30 Correct 16 ms 6488 KB Output is correct
31 Correct 3 ms 6488 KB Output is correct
32 Correct 2 ms 6488 KB Output is correct
33 Correct 3 ms 6488 KB Output is correct
34 Correct 2 ms 6488 KB Output is correct
35 Correct 5 ms 6488 KB Output is correct
36 Correct 2 ms 6488 KB Output is correct
37 Correct 17 ms 6488 KB Output is correct
38 Correct 18 ms 6488 KB Output is correct
39 Correct 2 ms 6488 KB Output is correct
40 Correct 3 ms 6488 KB Output is correct
41 Correct 3 ms 6488 KB Output is correct
42 Correct 3 ms 6488 KB Output is correct
43 Execution timed out 3061 ms 6488 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 3 ms 6488 KB Output is correct
3 Correct 16 ms 6740 KB Output is correct
4 Correct 16 ms 6488 KB Output is correct
5 Correct 16 ms 6488 KB Output is correct
6 Correct 20 ms 6488 KB Output is correct
7 Correct 17 ms 6488 KB Output is correct
8 Correct 19 ms 6488 KB Output is correct
9 Correct 3 ms 6488 KB Output is correct
10 Correct 2 ms 6488 KB Output is correct
11 Correct 2 ms 6488 KB Output is correct
12 Correct 2 ms 6488 KB Output is correct
13 Correct 3 ms 6488 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 3 ms 6488 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 2 ms 6488 KB Output is correct
18 Correct 2 ms 6488 KB Output is correct
19 Correct 3 ms 6488 KB Output is correct
20 Correct 2 ms 6488 KB Output is correct
21 Correct 2 ms 6488 KB Output is correct
22 Correct 2 ms 6488 KB Output is correct
23 Correct 2 ms 6488 KB Output is correct
24 Correct 3 ms 6488 KB Output is correct
25 Correct 2 ms 6488 KB Output is correct
26 Correct 4 ms 6488 KB Output is correct
27 Correct 2 ms 6488 KB Output is correct
28 Correct 2 ms 6488 KB Output is correct
29 Correct 16 ms 6556 KB Output is correct
30 Correct 16 ms 6488 KB Output is correct
31 Correct 3 ms 6488 KB Output is correct
32 Correct 2 ms 6488 KB Output is correct
33 Correct 3 ms 6488 KB Output is correct
34 Correct 2 ms 6488 KB Output is correct
35 Correct 5 ms 6488 KB Output is correct
36 Correct 2 ms 6488 KB Output is correct
37 Correct 17 ms 6488 KB Output is correct
38 Correct 18 ms 6488 KB Output is correct
39 Correct 2 ms 6488 KB Output is correct
40 Correct 3 ms 6488 KB Output is correct
41 Correct 3 ms 6488 KB Output is correct
42 Correct 3 ms 6488 KB Output is correct
43 Execution timed out 3010 ms 8316 KB Time limit exceeded
44 Halted 0 ms 0 KB -