답안 #1066897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1066897 2024-08-20T08:37:34 Z j_vdd16 디지털 회로 (IOI22_circuit) C++17
컴파일 오류
0 ms 0 KB
#include "circuit.h"

#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define int long long
#define loop(X, N) for(int X = 0; X < (N); X++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;


int n, m;
vvi children;
vector<signed> assignment;
vi c;
int dfs(int node) { //a
    if (node >= n) {
        return { assignment[node] };
    }

    vii counts; //c, a
    for (int child : children[node]) {
        int res = dfs(node);
        counts.push_back({c[child], res});
    }

    return counts[0].first * counts[1].second + counts[0].second * counts[1].first;
}
void cDfs(int node) {
    if (node >= n) {
        c[node] = 1;
    }

    c[node] = children[node].size();
    for (int child : children[node]) {
        cDfs(child);

        c[node] *= c[child];
    }
}

void init(signed N, signed M, std::vector<signed> P, std::vector<signed> A) {
    n = N;
    m = M;
    children = vvi(n);
    assignment = A;
    c = vi(n + m);

    for (int i = 1; i < n + m; i++) {
        children[P[i]].push_back(i);
    }

    cDfs(0);
}

int count_ways(int L, int R) {
    for (int i = L; i <= R; i++) {
        assignment[i] ^= 1;
    }

    return dfs(0);
    /*
    3 children:
    a = 
        1 * (a[0] * b[1] * b[2] + b[0] * a[1] * b[2] + b[0] * b[1] * a[2]) + 
        2 * (a[0] * a[1] * b[2] + a[0] * b[1] * a[2] + b[0] * a[1] * a[2]) +
        3 * (a[0] * a[1] * a[2])
      =
        1 * (a[0] * (c[1] - a[1]) * (c[2] - a[2]))
        2 * (a[0] * a[1] * (c[2] - a[2]))
        3 * (a[0] * a[1] * a[2])
      =
        (1 + 2 - 3) * (a[0] * a[1] * a[2])
        a[0] * c[1] * c[2]
        2 * (a[0] * a[1] * c[2]) - 2 * (a[0] * a[1] * c[2])
    
    C = c[0] * c[1] * c[2] * 3
    b = C - a
      = 

    2 children:
    a = 
        1 * (a[0] * b[1] + b[0] * a[1]) +
        2 * (a[0] * a[1])
      =
        1 * (a[0] * (c[1] - a[1]) + (c[0] - a[0]) * a[1]) +
        2 * (a[0] * a[1])
      = a[0] * c[1] + c[0] * a[1]
    
    C = c[0] * c[1] * 2
    b = C - a
      = 
    */

    //return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccEUqqpc.o: in function `main':
stub.cpp:(.text.startup+0x169): undefined reference to `count_ways(int, int)'
collect2: error: ld returned 1 exit status