Submission #683002

# Submission time Handle Problem Language Result Execution time Memory
683002 2023-01-17T13:22:23 Z sunwukong123 Digital Circuit (IOI22_circuit) C++17
18 / 100
43 ms 2300 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define FOR(i,s,e) for(int i = s; i <= (int)e; ++i)
#define DEC(i,s,e) for(int i = s; i >= (int)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
#define reach cerr << "LINE: " << __LINE__ << "\n";
#else
#define reach 
#define db(x)
#define db2(x,y)
#define db3(a,b,c)
#define dbv(v)
#define dbvp(v)
#define dba(a,ss,ee)
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define f first 
#define s second
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define g3(x) get<3>(x)
typedef pair <int, int> pi;
typedef tuple<int,int,int> ti3;
typedef tuple<int,int,int,int> ti4;
int rand(int a, int b) { return a + rng() % (b-a+1); }
const int MOD =  1'000'002'022;
const int inf = (int)1e9 + 500;
const long long oo = (long long)1e18 + 500;
template <typename T> bool chmax(T& a, const T b) { return a<b ? a = b, 1 : 0; }
template <typename T> bool chmin(T& a, const T b) { return a>b ? a = b, 1 : 0; }
const int MAXN = 2005;
int dp[MAXN][2]; // number of ways of this guy, being on/off
vector<int> V[MAXN];
int state[MAXN];
int n,m;
int dpdp(int x, bool on) {
    db2(x,on);
    if(~dp[x][on]) return dp[x][on];
    if(V[x].size() == 0) {
      //db(x);
      //db2(on,state[x-n]);
      if(on == state[x-n])return 1;
      else return 0;
    }
    int sz=V[x].size();
    int c[2][sz+5]; memset(c,0,sizeof c);
    c[0][0]=1; // there is 1 way of having no children and having no turned on children
    FOR(i,1,sz){

      int yes = dpdp(V[x][i-1], 1); // ways for this child to be on
      int no = dpdp(V[x][i-1], 0); // ways for this child to be off
      
      bool alt=i%2;
      memset(c[alt],0,sizeof c[alt]);
      FOR(j,0,i) {

        c[alt][j] = ((((j-1>=0)?c[1-alt][j-1]:0) * yes % MOD) + (c[1-alt][j] * no) % MOD)%MOD;
      }
    }
    bool lst=(sz)%2;
    if(on) {
      int ans = 0;
      FOR(i,1,sz) { // this is the capacity
        //for this to be okay, just make sure more than or equal i childs are turned on 
        int t = 0;
        FOR(j,i,sz) t=(t+c[lst][j])%MOD;
        ans = (ans + t) % MOD;
      }
      db3(x,on,ans);
      return dp[x][on] = ans;
    } else {
      int ans = 0;
      FOR(i,1,sz) { // this is the capacity
        //for this to be okay, just make sure less than i childs are turned on 
        int t = 0;
        FOR(j,0,i-1) t=(t+c[lst][j])%MOD;
        ans = (ans + t) % MOD;
      }
      db3(x,on,ans);
      return dp[x][on] = ans;
    }
    



}
void init(int32_t n, int32_t m, vector<int32_t> P, vector<int32_t> A) {
    ::n=n;
    ::m=m;
    FOR(i,1,n+m-1) {
      V[P[i]].pb(i);
    }
    FOR(i,0,m-1) {
      state[i]=A[i];
    }
}

int32_t count_ways(int32_t L, int32_t R) {
    FOR(i,L,R) {
      state[i-n]=!state[i-n];
    }
    memset(dp,-1,sizeof dp);
    int r= dpdp(0, 1);
    
    return r;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 19 ms 336 KB Output is correct
4 Correct 20 ms 336 KB Output is correct
5 Correct 20 ms 336 KB Output is correct
6 Correct 20 ms 336 KB Output is correct
7 Correct 22 ms 336 KB Output is correct
8 Correct 22 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 3 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 19 ms 336 KB Output is correct
4 Correct 20 ms 336 KB Output is correct
5 Correct 20 ms 336 KB Output is correct
6 Correct 20 ms 336 KB Output is correct
7 Correct 22 ms 336 KB Output is correct
8 Correct 22 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 3 ms 336 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 20 ms 336 KB Output is correct
30 Correct 20 ms 428 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 7 ms 336 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 43 ms 700 KB Output is correct
38 Correct 40 ms 592 KB Output is correct
39 Correct 2 ms 464 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 2300 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 2300 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 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 3 ms 336 KB Output is correct
13 Runtime error 14 ms 2300 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 19 ms 336 KB Output is correct
4 Correct 20 ms 336 KB Output is correct
5 Correct 20 ms 336 KB Output is correct
6 Correct 20 ms 336 KB Output is correct
7 Correct 22 ms 336 KB Output is correct
8 Correct 22 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 3 ms 336 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 20 ms 336 KB Output is correct
30 Correct 20 ms 428 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 7 ms 336 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 43 ms 700 KB Output is correct
38 Correct 40 ms 592 KB Output is correct
39 Correct 2 ms 464 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 2 ms 336 KB Output is correct
43 Runtime error 11 ms 932 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 19 ms 336 KB Output is correct
4 Correct 20 ms 336 KB Output is correct
5 Correct 20 ms 336 KB Output is correct
6 Correct 20 ms 336 KB Output is correct
7 Correct 22 ms 336 KB Output is correct
8 Correct 22 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 3 ms 336 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 20 ms 336 KB Output is correct
30 Correct 20 ms 428 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 2 ms 336 KB Output is correct
35 Correct 7 ms 336 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 43 ms 700 KB Output is correct
38 Correct 40 ms 592 KB Output is correct
39 Correct 2 ms 464 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 2 ms 336 KB Output is correct
43 Runtime error 14 ms 2300 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -