Submission #836313

# Submission time Handle Problem Language Result Execution time Memory
836313 2023-08-24T10:06:03 Z ma_moutahid Digital Circuit (IOI22_circuit) C++17
2 / 100
3000 ms 4560 KB
#include "circuit.h"
#include<bits/stdc++.h>
#include "circuit.h"
using namespace std;
#define vi vector<int>
#define vii vector<vi>
#define ll long long
#define vl vector<ll>
#include <cassert>
#include <cstdio>

int n,m;
vii g;
vl ways;
vl wb;
int mod=1000002022;

ll sum(ll a, ll b){
  return (a+b)%mod; 
}
ll diff(ll a, ll b){
  return(a-b+mod)%mod;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {

  n=N;
  m=M;
  g.resize(N+M);
  ways.resize(M+N);
  wb.resize(M+N);
  for(int i=1   ;i<N+M;i++){
    g[P[i]].push_back(i);
  }
  for(int i=N;i<N+M;i++){
    ways[i]=A[i-N];
    wb[i]=!ways[i];
  }

}

void dfs(int node){

  for(int child:g[node]){
    if(child>=n)continue;
    dfs(child);
  }

  int p=g[node].size();
  vl v(p+1);
  v[0]=1;

  for(int child:g[node]){
    vl copy(p+1);
    for(int i=0;i<=p;i++){
      if(i<p){
        copy[i+1]+=v[i+1]*wb[child]+v[i]*ways[child];
        copy[i+1]%=mod;
      }   
    }
    copy[0]=v[0]*wb[child];
    v=copy;
  }
  vl cum(p+1);
  cum[0]=v[0];
  for(int i=1;i<=p;i++){
    cum[i]=sum(cum[i-1],v[i]);
  }
  wb[node]=0;
  ways[node]=0;
  for(int i=1;i<=p;i++){
    wb[node]+=cum[i-1];
    wb[node]%=mod;
    ways[node]+=diff(cum[p],cum[i-1]);
    ways[node]%=mod;
  }
}

int count_ways(int L, int R) {

  for(int i=L;i<=R;i++){
    ways[i]=!ways[i];
    wb[i]=!wb[i];
  }

  dfs(0);
  return ways[0];
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 22 ms 356 KB Output is correct
4 Correct 23 ms 336 KB Output is correct
5 Correct 23 ms 336 KB Output is correct
6 Correct 23 ms 364 KB Output is correct
7 Correct 23 ms 360 KB Output is correct
8 Correct 23 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Incorrect 0 ms 336 KB 2nd lines differ - on the 1st token, expected: '785285606', found: '-214716416'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 22 ms 356 KB Output is correct
4 Correct 23 ms 336 KB Output is correct
5 Correct 23 ms 336 KB Output is correct
6 Correct 23 ms 364 KB Output is correct
7 Correct 23 ms 360 KB Output is correct
8 Correct 23 ms 352 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Incorrect 0 ms 336 KB 2nd lines differ - on the 1st token, expected: '785285606', found: '-214716416'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3031 ms 4560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3031 ms 4560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Incorrect 0 ms 336 KB 2nd lines differ - on the 1st token, expected: '785285606', found: '-214716416'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 22 ms 356 KB Output is correct
4 Correct 23 ms 336 KB Output is correct
5 Correct 23 ms 336 KB Output is correct
6 Correct 23 ms 364 KB Output is correct
7 Correct 23 ms 360 KB Output is correct
8 Correct 23 ms 352 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Incorrect 0 ms 336 KB 2nd lines differ - on the 1st token, expected: '785285606', found: '-214716416'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 22 ms 356 KB Output is correct
4 Correct 23 ms 336 KB Output is correct
5 Correct 23 ms 336 KB Output is correct
6 Correct 23 ms 364 KB Output is correct
7 Correct 23 ms 360 KB Output is correct
8 Correct 23 ms 352 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Incorrect 0 ms 336 KB 2nd lines differ - on the 1st token, expected: '785285606', found: '-214716416'
11 Halted 0 ms 0 KB -