답안 #1058527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058527 2024-08-14T10:35:30 Z SalihSahin 디지털 회로 (IOI22_circuit) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
#include "circuit.h"

const int M = 2000;

int mod = 10121101010

int add(int a, int b){
  return ((a%mod) + (b%mod))%mod;
}

int mul(int a, int b){
  return ((a%mod) * (b%mod))%mod;
}

vector<int> state(M);
vector<int> ch[2 * M];
int n;

pair<int, int> dfs(int node){ // {kac sekilde 0, kac sekilde 1}
  if(node >= n){
     if(state[node - n]) return {0, 1};
     else return {1, 0};
  }

  vector<pair<int, int> > sub;
  int c = ch[node].size();
  for(auto itr: ch[node]){
     sub.pb(dfs(itr));
  }

  vector<int> dp(c+1), ndp(c+1);
  dp[0] = 1;
  for(auto itr: sub){
    for(int i = 0; i <= c; i++){
       ndp[i] = 0;
       ndp[i] = add(ndp[i], mul(dp[i], itr.first));
       if(i) ndp[i] = add(ndp[i], mul(dp[i-1], itr.second));
    }
    dp = ndp;
  }

  pair<int, int> val;
  for(int i = 1; i <= c; i++){
    for(int j = 0; j <= c; j++){
       if(i > j) val.first = add(val.first, dp[j]);
       else val.second = add(val.second, dp[j]);
    }
  }

  return val;
}

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
   n = N;
   for(int i = 1; i < N + M; i++){
      ch[P[i]].pb(i);
   }
   for(int i = 0; i < M; i++) state[i] = A[i];
   return;
}

int count_ways(int L, int R) {
  L -= n;
  R -= n;

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

  pair<int, int> ans = dfs(0);
  return ans.second;
}

Compilation message

circuit.cpp:8:11: warning: overflow in conversion from 'long int' to 'int' changes value from '10121101010' to '1531166418' [-Woverflow]
    8 | int mod = 10121101010
      |           ^~~~~~~~~~~
circuit.cpp:10:1: error: expected ',' or ';' before 'int'
   10 | int add(int a, int b){
      | ^~~
circuit.cpp: In function 'std::pair<int, int> dfs(int)':
circuit.cpp:39:17: error: 'add' was not declared in this scope; did you mean 'std::filesystem::perm_options::add'?
   39 |        ndp[i] = add(ndp[i], mul(dp[i], itr.first));
      |                 ^~~
      |                 std::filesystem::perm_options::add
In file included from /usr/include/c++/10/filesystem:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from circuit.cpp:1:
/usr/include/c++/10/bits/fs_fwd.h:202:7: note: 'std::filesystem::perm_options::add' declared here
  202 |       add = 0x2,
      |       ^~~
circuit.cpp:48:30: error: 'add' was not declared in this scope; did you mean 'std::filesystem::perm_options::add'?
   48 |        if(i > j) val.first = add(val.first, dp[j]);
      |                              ^~~
      |                              std::filesystem::perm_options::add
In file included from /usr/include/c++/10/filesystem:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from circuit.cpp:1:
/usr/include/c++/10/bits/fs_fwd.h:202:7: note: 'std::filesystem::perm_options::add' declared here
  202 |       add = 0x2,
      |       ^~~
circuit.cpp:49:26: error: 'add' was not declared in this scope; did you mean 'std::filesystem::perm_options::add'?
   49 |        else val.second = add(val.second, dp[j]);
      |                          ^~~
      |                          std::filesystem::perm_options::add
In file included from /usr/include/c++/10/filesystem:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from circuit.cpp:1:
/usr/include/c++/10/bits/fs_fwd.h:202:7: note: 'std::filesystem::perm_options::add' declared here
  202 |       add = 0x2,
      |       ^~~