답안 #1064036

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064036 2024-08-18T08:37:48 Z ProtonDecay314 디지털 회로 (IOI22_circuit) C++17
0 / 100
3000 ms 5068 KB
// AM + DG
#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vpi> vvpi;
typedef vector<vpll> vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef short int si;
typedef vector<si> vsi;
typedef vector<vsi> vvsi;
#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define L(varll, mn, mx) for(ll varll = (mn); varll < (mx); varll++)
#define LR(varll, mx, mn) for(ll varll = (mx); varll > (mn); varll--)
#define LI(vari, mn, mx) for(int vari = (mn); vari < (mx); vari++)
#define LIR(vari, mx, mn) for(int vari = (mx); vari > (mn); vari--)
#define INPV(varvec) for(auto& varveci : (varvec)) cin >> varveci
#define fi first
#define se second
#define pb push_back
#define INF(type) numeric_limits<type>::max()
#define NINF(type) numeric_limits<type>::min()
#define TCASES int t; cin >> t; while(t--)

// ! It's not always the case that you can find a modular inverse...
// ! welp, that's sad, that means I don't get to optimize my dp transition
const ll MOD = 1'000'002'022ll;

vvll adj;
vll num_tot;
vll num_act;
vll a_ll;
ll n, m;

ll count_tot(ll i, const vvll& adj) {
    ll& ans = num_tot[i];

    if(ans == -1ll) {
        ans = max((ll)adj[i].size(), 1ll); // ! CAREFUL: cast to (ll) as needed!
        for(ll j : adj[i]) {
            ans = (ans * count_tot(j, adj)) % MOD;
        }
    }

    return ans;
}

ll count_act(ll i, const vvll& adj) {
    ll& ans = num_act[i];

    if(ans == -1ll) {
        vll c;

        ans = 0ll;

        ll nc = adj[i].size();

        for(ll j : adj[i]) {
            c.pb(count_act(j, adj));
        }

        L(ci, 0ll, nc) {
            ll prod = 1ll;

            L(ind, 0ll, nc) {
                if(ind == ci) prod = (prod * c[ind]) % MOD;
                else prod = (prod * num_tot[adj[i][ind]]) % MOD;
            }

            ans = (ans + prod) % MOD;
        }
    }

    return ans;
}

void init(int N, int M, vi P, vi A) {
    n = N; m = M;

    L(i, 1ll, N + M) {
        vll adjr;
        adj.pb(adjr);
    }

    L(i, 1ll, N + M) {
        adj[P[i]].pb(i);
    }

    num_tot.reserve(N + M);
    num_act.reserve(N + M);

    L(i, 0ll, N + M) {
        num_tot.pb(-1ll);
        num_act.pb(-1ll);
    }

    a_ll.reserve(M);

    for(int v : A) a_ll.pb((ll)v);

    copy(a_ll.begin(), a_ll.end(), next(num_act.begin(), n));

    count_tot(0ll, adj);

    count_act(0ll, adj);
}

int count_ways(int L, int R) {
    fill(num_act.begin(), next(num_act.begin(), n), -1ll); // Make -1 again

    L(i, L, R + 1ll) {
        num_act[i] = 1ll - num_act[i];
    }

    count_act(0ll, adj);

    // L(i, 0ll, n + m) {
    //     cout << num_act[i] << " ";
    // }
    // cout << "\n";
    // L(i, 0ll, n + m) {
    //     cout << num_tot[i] << " ";
    // }
    // cout << "\n";

    return count_act(0ll, adj);
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3019 ms 5068 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3019 ms 5068 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -