Submission #653110

# Submission time Handle Problem Language Result Execution time Memory
653110 2022-10-25T18:08:22 Z Lobo Digital Circuit (IOI22_circuit) C++17
2 / 100
14 ms 1340 KB
#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

const int maxn = 1010;
const int mod = 1e9+7;
int n, m, p[maxn], a[maxn];
vector<int> g[maxn];
int dp[maxn][2]; // dp[u][flag] = #ways I can be flag

void sol(int u) {
    if(u >= n) {
        dp[u][0] = dp[u][1] = 0;
        dp[u][a[u-n]] = 1;
        // cout << u << " " <<  dp[u][0] << " " << dp[u][1] << endl;
        return;
    }
    vector<int> qtd; // qtd[x] = # Ways I can have exactly x on
    for(int i = 0; i <= (int) g[u].size(); i++) {
        qtd.pb(0);
    }
    qtd[0] = 1;
    for(auto v : g[u]) {
        sol(v);
        for(int i = (int) g[u].size(); i >= 0; i--) {
            qtd[i] = qtd[i]*dp[v][0]+(i == 0 ? 0 : qtd[i-1])*dp[v][1];
            qtd[i]%= mod;
        }
    }

    dp[u][0] = dp[u][1] = 0;
    for(int i = 0; i <= (int) g[u].size(); i++) {
        dp[u][0]+= qtd[i]*((int) g[u].size() - i); dp[u][0]%= mod;
        dp[u][1]+= qtd[i]*i; dp[u][1]%= mod;
    }
    // cout << u << " " <<  dp[u][0] << " " << dp[u][1] << endl;

}

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++) {
        p[i] = P[i];
        g[p[i]].pb(i);
    }
    for(int i = 0; i < m; i++) {
        a[i] = A[i];
    }
}

int32_t count_ways(int32_t L, int32_t R) {
    for(int i = L; i <= R; i++) a[i-n]^=1;
    sol(0);
    return dp[0][1];
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 11 ms 336 KB Output is correct
4 Correct 12 ms 336 KB Output is correct
5 Correct 11 ms 336 KB Output is correct
6 Correct 11 ms 336 KB Output is correct
7 Correct 14 ms 336 KB Output is correct
8 Correct 10 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '52130940', found: '698211320'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 11 ms 336 KB Output is correct
4 Correct 12 ms 336 KB Output is correct
5 Correct 11 ms 336 KB Output is correct
6 Correct 11 ms 336 KB Output is correct
7 Correct 14 ms 336 KB Output is correct
8 Correct 10 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '52130940', found: '698211320'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 1340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 1340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '52130940', found: '698211320'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 11 ms 336 KB Output is correct
4 Correct 12 ms 336 KB Output is correct
5 Correct 11 ms 336 KB Output is correct
6 Correct 11 ms 336 KB Output is correct
7 Correct 14 ms 336 KB Output is correct
8 Correct 10 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '52130940', found: '698211320'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 11 ms 336 KB Output is correct
4 Correct 12 ms 336 KB Output is correct
5 Correct 11 ms 336 KB Output is correct
6 Correct 11 ms 336 KB Output is correct
7 Correct 14 ms 336 KB Output is correct
8 Correct 10 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '52130940', found: '698211320'
11 Halted 0 ms 0 KB -