답안 #829758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
829758 2023-08-18T14:48:38 Z beaconmc 디지털 회로 (IOI22_circuit) C++17
18 / 100
3000 ms 11556 KB
#include "circuit.h"


#include <bits/stdc++.h>

typedef long long ll;
using namespace std;


#define FOR(i, x, y) for(ll i=x; i<y; i++)
#define FORNEG(i, x, y) for(ll i=x; i>y; i--)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)


vector<ll> edges[100001];

ll possible[100001];
ll on[100001];
bool state[100001];



int initdfs(ll a){
  if (edges[a].size() == 0) return possible[a] = 1;

  ll temp = 1;
  for (auto&i : edges[a]){
    temp *= initdfs(i);
    temp %= 1000002022;
  }
  temp *= edges[a].size();
  temp %= 1000002022;


  return possible[a] = temp;
}

void dfs2(ll a){

  if (edges[a].size()==0){
    on[a] = state[a]; 
    return;
  } 

  ll dp[edges[a].size()+1][edges[a].size()+1];

  FOR(i,0,edges[a].size()+1) FOR(j,0,edges[a].size()+1) dp[i][j] = 0;
  dp[0][0] = 1;




  FOR(i,0,edges[a].size()){
    dfs2(edges[a][i]);
    FOR(j,0,edges[a].size()){
      dp[i+1][j] += (dp[i][j] * (possible[edges[a][i]] - on[edges[a][i]]))%1000002022;
      dp[i+1][j+1] += (dp[i][j] * on[edges[a][i]])%1000002022;

    }
  }


  ll ans = 0;
  ll cur = 0;
  FORNEG(i,edges[a].size(),0){
    ans +=  dp[edges[a].size()][i] * i;
    ans %= 1000002022;
  }

  
  
  on[a] = (ans+1000002022)%1000002022;

}


void init(int N, int M, std::vector<int> P, std::vector<int> A) {
  FOR(i,1,N+M){
    edges[P[i]].push_back(i);
  }
  FOR(i,N,N+M){
    state[i] = A[i-N];
  }
  initdfs(0);

}



int count_ways(int L, int R) {

  FOR(i,0,100001) on[i] = -1;
  FOR(i,L,R+1){
    state[i] = (state[i]+1)%2;
  }

  dfs2(0);
  return on[0];
}

Compilation message

circuit.cpp: In function 'void dfs2(ll)':
circuit.cpp:10:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define FOR(i, x, y) for(ll i=x; i<y; i++)
......
   47 |   FOR(i,0,edges[a].size()+1) FOR(j,0,edges[a].size()+1) dp[i][j] = 0;
      |       ~~~~~~~~~~~~~~~~~~~~~        
circuit.cpp:47:3: note: in expansion of macro 'FOR'
   47 |   FOR(i,0,edges[a].size()+1) FOR(j,0,edges[a].size()+1) dp[i][j] = 0;
      |   ^~~
circuit.cpp:10:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define FOR(i, x, y) for(ll i=x; i<y; i++)
......
   47 |   FOR(i,0,edges[a].size()+1) FOR(j,0,edges[a].size()+1) dp[i][j] = 0;
      |                                  ~~~~~~~~~~~~~~~~~~~~~
circuit.cpp:47:30: note: in expansion of macro 'FOR'
   47 |   FOR(i,0,edges[a].size()+1) FOR(j,0,edges[a].size()+1) dp[i][j] = 0;
      |                              ^~~
circuit.cpp:10:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define FOR(i, x, y) for(ll i=x; i<y; i++)
......
   53 |   FOR(i,0,edges[a].size()){
      |       ~~~~~~~~~~~~~~~~~~~          
circuit.cpp:53:3: note: in expansion of macro 'FOR'
   53 |   FOR(i,0,edges[a].size()){
      |   ^~~
circuit.cpp:10:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define FOR(i, x, y) for(ll i=x; i<y; i++)
......
   55 |     FOR(j,0,edges[a].size()){
      |         ~~~~~~~~~~~~~~~~~~~        
circuit.cpp:55:5: note: in expansion of macro 'FOR'
   55 |     FOR(j,0,edges[a].size()){
      |     ^~~
circuit.cpp:64:6: warning: unused variable 'cur' [-Wunused-variable]
   64 |   ll cur = 0;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 19 ms 10832 KB Output is correct
4 Correct 27 ms 11316 KB Output is correct
5 Correct 22 ms 11256 KB Output is correct
6 Correct 21 ms 11216 KB Output is correct
7 Correct 22 ms 11216 KB Output is correct
8 Correct 20 ms 11216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 3 ms 3408 KB Output is correct
3 Correct 2 ms 3408 KB Output is correct
4 Correct 2 ms 3408 KB Output is correct
5 Correct 2 ms 3408 KB Output is correct
6 Correct 2 ms 3408 KB Output is correct
7 Correct 2 ms 3408 KB Output is correct
8 Correct 3 ms 3408 KB Output is correct
9 Correct 3 ms 3408 KB Output is correct
10 Correct 3 ms 3664 KB Output is correct
11 Correct 3 ms 3684 KB Output is correct
12 Correct 3 ms 3408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 19 ms 10832 KB Output is correct
4 Correct 27 ms 11316 KB Output is correct
5 Correct 22 ms 11256 KB Output is correct
6 Correct 21 ms 11216 KB Output is correct
7 Correct 22 ms 11216 KB Output is correct
8 Correct 20 ms 11216 KB Output is correct
9 Correct 2 ms 3408 KB Output is correct
10 Correct 3 ms 3408 KB Output is correct
11 Correct 2 ms 3408 KB Output is correct
12 Correct 2 ms 3408 KB Output is correct
13 Correct 2 ms 3408 KB Output is correct
14 Correct 2 ms 3408 KB Output is correct
15 Correct 2 ms 3408 KB Output is correct
16 Correct 3 ms 3408 KB Output is correct
17 Correct 3 ms 3408 KB Output is correct
18 Correct 3 ms 3664 KB Output is correct
19 Correct 3 ms 3684 KB Output is correct
20 Correct 3 ms 3408 KB Output is correct
21 Correct 2 ms 3408 KB Output is correct
22 Correct 2 ms 3408 KB Output is correct
23 Correct 2 ms 3408 KB Output is correct
24 Correct 2 ms 3408 KB Output is correct
25 Correct 2 ms 3408 KB Output is correct
26 Correct 2 ms 3408 KB Output is correct
27 Correct 3 ms 3408 KB Output is correct
28 Correct 2 ms 3408 KB Output is correct
29 Correct 23 ms 11228 KB Output is correct
30 Correct 20 ms 11216 KB Output is correct
31 Correct 2 ms 3664 KB Output is correct
32 Correct 2 ms 3416 KB Output is correct
33 Correct 3 ms 3408 KB Output is correct
34 Correct 2 ms 3408 KB Output is correct
35 Correct 6 ms 4944 KB Output is correct
36 Correct 3 ms 3664 KB Output is correct
37 Correct 21 ms 11556 KB Output is correct
38 Correct 20 ms 11472 KB Output is correct
39 Correct 2 ms 3408 KB Output is correct
40 Correct 2 ms 3408 KB Output is correct
41 Correct 2 ms 3408 KB Output is correct
42 Correct 2 ms 3408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3094 ms 5348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3094 ms 5348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 3 ms 3408 KB Output is correct
3 Correct 2 ms 3408 KB Output is correct
4 Correct 2 ms 3408 KB Output is correct
5 Correct 2 ms 3408 KB Output is correct
6 Correct 2 ms 3408 KB Output is correct
7 Correct 2 ms 3408 KB Output is correct
8 Correct 3 ms 3408 KB Output is correct
9 Correct 3 ms 3408 KB Output is correct
10 Correct 3 ms 3664 KB Output is correct
11 Correct 3 ms 3684 KB Output is correct
12 Correct 3 ms 3408 KB Output is correct
13 Execution timed out 3094 ms 5348 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 19 ms 10832 KB Output is correct
4 Correct 27 ms 11316 KB Output is correct
5 Correct 22 ms 11256 KB Output is correct
6 Correct 21 ms 11216 KB Output is correct
7 Correct 22 ms 11216 KB Output is correct
8 Correct 20 ms 11216 KB Output is correct
9 Correct 2 ms 3408 KB Output is correct
10 Correct 3 ms 3408 KB Output is correct
11 Correct 2 ms 3408 KB Output is correct
12 Correct 2 ms 3408 KB Output is correct
13 Correct 2 ms 3408 KB Output is correct
14 Correct 2 ms 3408 KB Output is correct
15 Correct 2 ms 3408 KB Output is correct
16 Correct 3 ms 3408 KB Output is correct
17 Correct 3 ms 3408 KB Output is correct
18 Correct 3 ms 3664 KB Output is correct
19 Correct 3 ms 3684 KB Output is correct
20 Correct 3 ms 3408 KB Output is correct
21 Correct 2 ms 3408 KB Output is correct
22 Correct 2 ms 3408 KB Output is correct
23 Correct 2 ms 3408 KB Output is correct
24 Correct 2 ms 3408 KB Output is correct
25 Correct 2 ms 3408 KB Output is correct
26 Correct 2 ms 3408 KB Output is correct
27 Correct 3 ms 3408 KB Output is correct
28 Correct 2 ms 3408 KB Output is correct
29 Correct 23 ms 11228 KB Output is correct
30 Correct 20 ms 11216 KB Output is correct
31 Correct 2 ms 3664 KB Output is correct
32 Correct 2 ms 3416 KB Output is correct
33 Correct 3 ms 3408 KB Output is correct
34 Correct 2 ms 3408 KB Output is correct
35 Correct 6 ms 4944 KB Output is correct
36 Correct 3 ms 3664 KB Output is correct
37 Correct 21 ms 11556 KB Output is correct
38 Correct 20 ms 11472 KB Output is correct
39 Correct 2 ms 3408 KB Output is correct
40 Correct 2 ms 3408 KB Output is correct
41 Correct 2 ms 3408 KB Output is correct
42 Correct 2 ms 3408 KB Output is correct
43 Execution timed out 3096 ms 3664 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3408 KB Output is correct
2 Correct 2 ms 3408 KB Output is correct
3 Correct 19 ms 10832 KB Output is correct
4 Correct 27 ms 11316 KB Output is correct
5 Correct 22 ms 11256 KB Output is correct
6 Correct 21 ms 11216 KB Output is correct
7 Correct 22 ms 11216 KB Output is correct
8 Correct 20 ms 11216 KB Output is correct
9 Correct 2 ms 3408 KB Output is correct
10 Correct 3 ms 3408 KB Output is correct
11 Correct 2 ms 3408 KB Output is correct
12 Correct 2 ms 3408 KB Output is correct
13 Correct 2 ms 3408 KB Output is correct
14 Correct 2 ms 3408 KB Output is correct
15 Correct 2 ms 3408 KB Output is correct
16 Correct 3 ms 3408 KB Output is correct
17 Correct 3 ms 3408 KB Output is correct
18 Correct 3 ms 3664 KB Output is correct
19 Correct 3 ms 3684 KB Output is correct
20 Correct 3 ms 3408 KB Output is correct
21 Correct 2 ms 3408 KB Output is correct
22 Correct 2 ms 3408 KB Output is correct
23 Correct 2 ms 3408 KB Output is correct
24 Correct 2 ms 3408 KB Output is correct
25 Correct 2 ms 3408 KB Output is correct
26 Correct 2 ms 3408 KB Output is correct
27 Correct 3 ms 3408 KB Output is correct
28 Correct 2 ms 3408 KB Output is correct
29 Correct 23 ms 11228 KB Output is correct
30 Correct 20 ms 11216 KB Output is correct
31 Correct 2 ms 3664 KB Output is correct
32 Correct 2 ms 3416 KB Output is correct
33 Correct 3 ms 3408 KB Output is correct
34 Correct 2 ms 3408 KB Output is correct
35 Correct 6 ms 4944 KB Output is correct
36 Correct 3 ms 3664 KB Output is correct
37 Correct 21 ms 11556 KB Output is correct
38 Correct 20 ms 11472 KB Output is correct
39 Correct 2 ms 3408 KB Output is correct
40 Correct 2 ms 3408 KB Output is correct
41 Correct 2 ms 3408 KB Output is correct
42 Correct 2 ms 3408 KB Output is correct
43 Execution timed out 3094 ms 5348 KB Time limit exceeded
44 Halted 0 ms 0 KB -