답안 #876341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876341 2023-11-21T14:58:07 Z Halfjuice 디지털 회로 (IOI22_circuit) C++17
0 / 100
418 ms 5580 KB
#include <iostream>

#include <vector>

using namespace std;

long modPow(long b, long e, long m)
{
    b = b%m;
    long r = 1;
    while (e>0) {
        if (e%2 == 1) {
            r = (r*b) % m;
        }
        b = (b*b)%m;
        e >>= 1;
    }
    return r;
}

#define MOD 1000002022

typedef struct _Node {
    _Node* parent;
    vector<_Node*> children;
    
    int index;
    int internalNodeCount;
    long contribCount;
  
    void initAny() {
        internalNodeCount = 0;
        contribCount = 0;
    
        for (auto it=children.begin(); it!=children.end(); ++it) {
            (*it)->initAny();
            if ((*it)->children.size() > 0) {
                internalNodeCount += (*it)->internalNodeCount;
            }
        }
        if (children.size() > 0) {
            internalNodeCount += 1;
        }
    }
  
    long searchPathUp(bool start, _Node* child) {
        long res = 1;
        if (!start) {
            res = modPow(2, internalNodeCount-1-child->internalNodeCount, MOD);
        }
        if (parent) {
            res = (res*parent->searchPathUp(false, this)) % MOD;
        }
        return res;
    }
    
    void print() {
        cout << "N" << index << " C=" << children.size() << " IC=" << internalNodeCount << " Ct=" << contribCount << endl;
    }
  
    void initLeaf() {
        if (this->children.size() == 0) {
            contribCount = parent->searchPathUp(true, this);
        }
    }
} Node;
 
vector<Node> nodes;
vector<int> state;
long cur;
int n, m;
 
//#define DEBUG_PRINT(nodes) for (int i=0; i<N+M; i++) nodes[i].print(); 
#define DEBUG_PRINT(nodes)

void init(int N, int M, vector<int> P, vector<int> A) {
    n = N;
    m = M;
    nodes.empty();
    for (int i=0; i<N+M; i++) {
        nodes.push_back(Node());
    }
    for (int i=0; i<N+M; i++) {
        if (P[i] == -1) {
            nodes[i].parent = 0;
        } else {
            nodes[i].parent = &(nodes[P[i]]);
            nodes[P[i]].children.push_back(&(nodes[i]));
            nodes[i].index = i;
        }
    }
    
    DEBUG_PRINT(nodes)
    nodes[0].initAny();
    DEBUG_PRINT(nodes)
  
    for (int i=N; i<N+M; i++) {
        nodes[i].initLeaf();
    }
    
    DEBUG_PRINT(nodes)
    
    state = A;
    cur = 0;
    for (int i=0; i<M; i++) {
        cur = (cur + nodes[N+i].contribCount*state[i]) % MOD;
    }
}
 
int count_ways(int L, int R) {
    for (int i=L; i<R; i++) {
        if (state[i]) {
            state[i] = 0;
            cur = (cur - nodes[n+i].contribCount) % MOD;
        } else {
            state[i] = 1;
            cur = (cur + nodes[n+i].contribCount) % MOD;
        }
    }
    if (cur < 0) {
        cur = cur + MOD;
    }
    return cur;
}

Compilation message

circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:79:16: warning: ignoring return value of 'bool std::vector<_Tp, _Alloc>::empty() const [with _Tp = _Node; _Alloc = std::allocator<_Node>]', declared with attribute 'nodiscard' [-Wunused-result]
   79 |     nodes.empty();
      |     ~~~~~~~~~~~^~
In file included from /usr/include/c++/10/vector:67,
                 from circuit.cpp:3:
/usr/include/c++/10/bits/stl_vector.h:1007:7: note: declared here
 1007 |       empty() const _GLIBCXX_NOEXCEPT
      |       ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 356 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 418 ms 5580 KB 1st lines differ - on the 1st token, expected: '431985922', found: '394586018'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 418 ms 5580 KB 1st lines differ - on the 1st token, expected: '431985922', found: '394586018'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 356 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -