Submission #830942

# Submission time Handle Problem Language Result Execution time Memory
830942 2023-08-19T13:24:05 Z beaconmc Digital Circuit (IOI22_circuit) C++17
9 / 100
3000 ms 6260 KB
#include "circuit.h"


#include <bits/stdc++.h>

typedef long long ll;
using namespace std;


#define FOR(i, x, y) for(ll i=x; i<y; i++)
#define FORNEG(i, x, y) for(ll i=x; i>y; i--)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)


vector<ll> edges[100001];
ll possible[100001];
ll contrib[100001];
ll dps[100001];
vector<int> p;
bool state[100001];



int initdfs(ll a){
  if (edges[a].size() == 0) return possible[a] = 1;

  ll temp = 1;
  for (auto&i : edges[a]){
    temp *= initdfs(i);
    temp %= 1000002022;
  }
  temp *= edges[a].size();
  temp %= 1000002022;


  return possible[a] = temp;
}

int dp(ll a){
  if (a==0) return 1;
  if (dps[a] != -1) return dps[a];

  ll temp = 1;

  for (auto&i : edges[p[a]]){
    if (i != a) temp *= possible[i];
  }
  dps[a] = temp * dp(p[a]) % 1000002022;
  return dps[a];
}

ll n,m;

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
  FOR(i,0,100001) dps[i] = -1;
  p = P;
  n = N;
  m = M;
  FOR(i,1,N+M){
    edges[P[i]].push_back(i);
  }
  FOR(i,N,N+M){
    state[i] = A[i-N];
  }
  initdfs(0);


  FOR(i,N,N+M){
    ll temp = possible[i];
    temp *= dp(i);
    contrib[i] = temp%1000002022;
  }

}


int count_ways(int L, int R) {
  FOR(i,L,R+1){
    state[i] = (state[i]+1)%2;
  }
  ll ans = 0;

  FOR(i,n,n+m){
    if (state[i]) ans += contrib[i];
  }
  return ans%1000002022;

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 3 ms 3408 KB Output is correct
4 Correct 3 ms 3408 KB Output is correct
5 Correct 3 ms 3408 KB Output is correct
6 Correct 3 ms 3408 KB Output is correct
7 Correct 3 ms 3408 KB Output is correct
8 Correct 3 ms 3408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 2 ms 3408 KB Output is correct
4 Correct 2 ms 3408 KB Output is correct
5 Correct 2 ms 3408 KB Output is correct
6 Correct 2 ms 3408 KB Output is correct
7 Correct 2 ms 3536 KB Output is correct
8 Correct 2 ms 3536 KB Output is correct
9 Correct 2 ms 3536 KB Output is correct
10 Correct 2 ms 3536 KB Output is correct
11 Correct 2 ms 3536 KB Output is correct
12 Correct 2 ms 3408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 3 ms 3408 KB Output is correct
4 Correct 3 ms 3408 KB Output is correct
5 Correct 3 ms 3408 KB Output is correct
6 Correct 3 ms 3408 KB Output is correct
7 Correct 3 ms 3408 KB Output is correct
8 Correct 3 ms 3408 KB Output is correct
9 Correct 2 ms 3408 KB Output is correct
10 Correct 2 ms 3408 KB Output is correct
11 Correct 2 ms 3408 KB Output is correct
12 Correct 2 ms 3408 KB Output is correct
13 Correct 2 ms 3408 KB Output is correct
14 Correct 2 ms 3408 KB Output is correct
15 Correct 2 ms 3536 KB Output is correct
16 Correct 2 ms 3536 KB Output is correct
17 Correct 2 ms 3536 KB Output is correct
18 Correct 2 ms 3536 KB Output is correct
19 Correct 2 ms 3536 KB Output is correct
20 Correct 2 ms 3408 KB Output is correct
21 Incorrect 2 ms 3408 KB 1st lines differ - on the 1st token, expected: '759476520', found: '202624978'
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3064 ms 6260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3064 ms 6260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 2 ms 3408 KB Output is correct
4 Correct 2 ms 3408 KB Output is correct
5 Correct 2 ms 3408 KB Output is correct
6 Correct 2 ms 3408 KB Output is correct
7 Correct 2 ms 3536 KB Output is correct
8 Correct 2 ms 3536 KB Output is correct
9 Correct 2 ms 3536 KB Output is correct
10 Correct 2 ms 3536 KB Output is correct
11 Correct 2 ms 3536 KB Output is correct
12 Correct 2 ms 3408 KB Output is correct
13 Execution timed out 3064 ms 6260 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 3 ms 3408 KB Output is correct
4 Correct 3 ms 3408 KB Output is correct
5 Correct 3 ms 3408 KB Output is correct
6 Correct 3 ms 3408 KB Output is correct
7 Correct 3 ms 3408 KB Output is correct
8 Correct 3 ms 3408 KB Output is correct
9 Correct 2 ms 3408 KB Output is correct
10 Correct 2 ms 3408 KB Output is correct
11 Correct 2 ms 3408 KB Output is correct
12 Correct 2 ms 3408 KB Output is correct
13 Correct 2 ms 3408 KB Output is correct
14 Correct 2 ms 3408 KB Output is correct
15 Correct 2 ms 3536 KB Output is correct
16 Correct 2 ms 3536 KB Output is correct
17 Correct 2 ms 3536 KB Output is correct
18 Correct 2 ms 3536 KB Output is correct
19 Correct 2 ms 3536 KB Output is correct
20 Correct 2 ms 3408 KB Output is correct
21 Incorrect 2 ms 3408 KB 1st lines differ - on the 1st token, expected: '759476520', found: '202624978'
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 3 ms 3408 KB Output is correct
4 Correct 3 ms 3408 KB Output is correct
5 Correct 3 ms 3408 KB Output is correct
6 Correct 3 ms 3408 KB Output is correct
7 Correct 3 ms 3408 KB Output is correct
8 Correct 3 ms 3408 KB Output is correct
9 Correct 2 ms 3408 KB Output is correct
10 Correct 2 ms 3408 KB Output is correct
11 Correct 2 ms 3408 KB Output is correct
12 Correct 2 ms 3408 KB Output is correct
13 Correct 2 ms 3408 KB Output is correct
14 Correct 2 ms 3408 KB Output is correct
15 Correct 2 ms 3536 KB Output is correct
16 Correct 2 ms 3536 KB Output is correct
17 Correct 2 ms 3536 KB Output is correct
18 Correct 2 ms 3536 KB Output is correct
19 Correct 2 ms 3536 KB Output is correct
20 Correct 2 ms 3408 KB Output is correct
21 Incorrect 2 ms 3408 KB 1st lines differ - on the 1st token, expected: '759476520', found: '202624978'
22 Halted 0 ms 0 KB -