답안 #1058513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058513 2024-08-14T10:26:32 Z SalihSahin 디지털 회로 (IOI22_circuit) C++17
2 / 100
10 ms 2392 KB
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
#include "circuit.h"

const int M = 2000;

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] = dp[i] * itr.first;
    }
    for(int i = 1; i <= c; i++){
       ndp[i] += 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 += dp[j];
       else 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;
}

/*
int main() {
  int N, M, Q;
  assert(3 == scanf("%d %d %d", &N, &M, &Q));
  std::vector<int> P(N + M), A(M);
  for (int i = 0; i < N + M; ++i) {
    assert(1 == scanf("%d", &P[i]));
  }
  for (int j = 0; j < M; ++j) {
    assert(1 == scanf("%d", &A[j]));
  }
  init(N, M, P, A);

  for (int i = 0; i < Q; ++i) {
    int L, R;
    assert(2 == scanf("%d %d", &L, &R));
    printf("%d\n", count_ways(L, R));
  }
  return 0;
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 2392 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 2392 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '0'
11 Halted 0 ms 0 KB -