Submission #888195

# Submission time Handle Problem Language Result Execution time Memory
888195 2023-12-16T10:17:56 Z Ludissey Digital Circuit (IOI22_circuit) C++17
11 / 100
3000 ms 2097152 KB
#include "circuit.h"
 
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
 
int N,M;
const int MOD=1e9+2022;
vector<vector<int>> tree;
vector<int> p;
vector<vector<bool>> toChange;
vector<int> state;
vector<int> depth;
vector<int> poss;
vector<vector<int>> memo;
 
int dfs(int i, int on){
  if(i>=N){
    toChange[i][on]=false;
    if(on) return state[i];
    else return 1-state[i];
  }
  if(memo[i][on]!=-1&&!toChange[i][on]) return memo[i][on];
  int lo=dfs(tree[i][0],true)%MOD, lf=dfs(tree[i][0],false)%MOD;
  int ro=dfs(tree[i][1],true)%MOD, rf=dfs(tree[i][1],false)%MOD;
  int ret=(lo*rf)%MOD+(ro*lf)%MOD;
  toChange[i][on]=false;
  if(on) ret+=(lo*ro*2)%MOD;
  else ret+=(2*lf*rf)%MOD;
  return memo[i][on]=ret%MOD;
}
 
void changeVec(int i){
  toChange[i][0]=true;
  toChange[i][1]=true;
  if(i==0) return;
  changeVec(p[i]);
}
 
void init(signed n, signed m, std::vector<signed> P, std::vector<signed> A) {
  N=n; M=m;
  p.resize(N+M);
  for (int i = 0; i < N+M; i++) p[i]=P[i];
  tree.resize(N+M); state.resize(N+M);
  toChange.resize(N+M,vector<bool>(2, false));
  memo.resize(N+M, vector<int>(2,-1));
  for (int i = 1; i < N+M; i++) tree[P[i]].push_back(i);
  for (int i = N; i < N+M; i++) state[i] = A[i-N];
  dfs(0,true);
}
 
signed count_ways(signed L, signed R) {
  for (int i = L; i <= R; i++) state[i] = 1-state[i];
  for (int i = L; i <= R; i++) changeVec(i);
  signed d=dfs(0,true)%MOD;
  if(N==1){
    d=0;
    for (int i = N; i < N+M; i++) d+=state[i];
  }
  return d;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1615 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 4 ms 1108 KB Output is correct
11 Correct 6 ms 856 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1615 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 500 ms 12868 KB Output is correct
2 Correct 782 ms 25532 KB Output is correct
3 Correct 845 ms 25536 KB Output is correct
4 Correct 844 ms 25508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 500 ms 12868 KB Output is correct
2 Correct 782 ms 25532 KB Output is correct
3 Correct 845 ms 25536 KB Output is correct
4 Correct 844 ms 25508 KB Output is correct
5 Execution timed out 3085 ms 12872 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 4 ms 1108 KB Output is correct
11 Correct 6 ms 856 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 500 ms 12868 KB Output is correct
14 Correct 782 ms 25532 KB Output is correct
15 Correct 845 ms 25536 KB Output is correct
16 Correct 844 ms 25508 KB Output is correct
17 Execution timed out 3085 ms 12872 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1615 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1615 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -