Submission #803179

# Submission time Handle Problem Language Result Execution time Memory
803179 2023-08-03T00:05:31 Z yeyso Digital Circuit (IOI22_circuit) C++17
0 / 100
15 ms 7972 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

#include <vector>
vector<int> dp0;
vector<int> dp1;
vector<vector<int>> adj;
void dfs(int u, int v){

  if(adj[u].size() == 2){
      int l = adj[u][0];
      int r = adj[u][1];
      dfs(l, u);
      dfs(r, u);
    
      dp0[u] = dp1[l] * dp0[r] + dp1[r] * dp0[l] + 2 * dp0[l] * dp0[r];
      dp1[u] = dp1[l] * dp0[r] + dp1[r] * dp0[l] + 2 * dp1[l] * dp1[r];
  } else {

  }
}

int n, m;
void init(int N, int M, vector<int> P, vector<int> A) {
    n = N; m = M;
    dp0.resize(N+M, 0);
    dp1.resize(N+M, 0);
    
    for(int i = 0; i < A.size(); i ++){
        dp0[i+N] = A[i] ^ 1;
        dp1[i+N] = A[i]; 
    }

    vector<vector<int>> adj0(N, vector<int>());
    for(int i = 0; i < P.size(); i ++){
        //adj0[i].push_back(P[i]);
        if(i != 0) adj0[P[i]].push_back(i);
    }

    adj = adj0;
}

int count_ways(int L, int R) {
    //return 0;

    for(int i = L+n; i <= R+n; i ++){
        dp0[i] = dp0[i] ^ 1;
        dp1[i] = dp1[i] ^ 1;
    }

    dfs(0, 0);
    return dp1[0];
}
/*
g++ -std=gnu++17 -O2 -Wall -pipe -static -o circuit stub.cpp circuit.cpp

dp1[i] = dp1[u] * dp0[v] + dp0[u] * dp1[v] + 2 * dp1[u] * dp1[v]

3 4 3
-1 0 1 2 1 1 0
1 0 1 0
3 4
4 5
3 6

*/

Compilation message

circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i = 0; i < A.size(); i ++){
      |                    ~~^~~~~~~~~~
circuit.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i = 0; i < P.size(); i ++){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 7972 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 7972 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -