Submission #807595

# Submission time Handle Problem Language Result Execution time Memory
807595 2023-08-04T20:02:06 Z Ozy Digital Circuit (IOI22_circuit) C++17
2 / 100
8 ms 2128 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>

#define MAX 1000
//para el arreglo
#define unos first
#define ceros second

vector<lli> hijos[MAX+2];
lli n,m;
lli dp[MAX+2][MAX+2];
pll arr[MAX+2];

pll solve(lli pos) {
  pll res = {0,0};
  lli sig,apu = 0;
  lli tam = hijos[pos].size();
  rep(i,0,tam) dp[apu][i] = 0;
  dp[apu][0] = 1;

  for(auto h : hijos[pos]) {
    sig = apu^1;
    rep(i,0,tam) dp[sig][i] = 0;

    rep(i,0,tam) {
      dp[sig][i] += dp[apu][i] * arr[h].ceros;
      dp[sig][i+1] += dp[apu][i] * arr[h].unos;
    }

    apu = sig;
  }

  lli u = 0;
  lli c = tam;
  rep(i,0,tam) {
    res.unos += dp[apu][i]*u;
    res.ceros += dp[apu][i]*c;
    u++;
    c--;
  }
  return res;
}

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
  n = N;
  m=M;
    
  rep(i,1,N+M-1) hijos[P[i]].push_back(i);
  rep(i,0,M-1) {
    if (A[i] == 0) arr[i+n] = {0,1};
    else arr[i+n] = {1,0};
  }
  repa(i,n-1,0) arr[i] = solve(i);
}

int count_ways(int L, int R) {

  rep(i,L,R) {
    arr[i].unos ^= 1;
    arr[i].ceros ^= 1;
  }
  repa(i,n-1,0) arr[i] = solve(i);
  return arr[0].unos;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 7 ms 336 KB Output is correct
4 Correct 7 ms 336 KB Output is correct
5 Correct 7 ms 336 KB Output is correct
6 Correct 7 ms 336 KB Output is correct
7 Correct 7 ms 336 KB Output is correct
8 Correct 7 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 7 ms 336 KB Output is correct
4 Correct 7 ms 336 KB Output is correct
5 Correct 7 ms 336 KB Output is correct
6 Correct 7 ms 336 KB Output is correct
7 Correct 7 ms 336 KB Output is correct
8 Correct 7 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 2128 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 2128 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 7 ms 336 KB Output is correct
4 Correct 7 ms 336 KB Output is correct
5 Correct 7 ms 336 KB Output is correct
6 Correct 7 ms 336 KB Output is correct
7 Correct 7 ms 336 KB Output is correct
8 Correct 7 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 7 ms 336 KB Output is correct
4 Correct 7 ms 336 KB Output is correct
5 Correct 7 ms 336 KB Output is correct
6 Correct 7 ms 336 KB Output is correct
7 Correct 7 ms 336 KB Output is correct
8 Correct 7 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -