답안 #697352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697352 2023-02-09T12:11:19 Z FEDIKUS 디지털 회로 (IOI22_circuit) C++17
46 / 100
3000 ms 7504 KB
#include "circuit.h"

#include<bits/stdc++.h>
#include <vector>

using namespace std;

typedef long long ll;

const int maxn=2e5+10;
const int mod=1e9+2022;

int n,m;

vector<int> g[maxn];
vector<int> p,a;

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

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

int bruk[maxn];
int power[maxn];

void dfs(int node){
  bruk[node]=1;
  if(node<n) bruk[node]=mul(bruk[node],g[node].size());
  for(int i:g[node]){
    dfs(i);
    bruk[node]=mul(bruk[node],bruk[i]);
  }
}

void dfs2(int node,int tren){
  if(node>=n){
    power[node-n]=tren;
    return;
  }
  vector<int> pref(g[node].size());
  vector<int> suf(g[node].size());
  for(int i=0;i<(int)g[node].size();i++){
    if(i==0) pref[i]=bruk[g[node][i]];
    else pref[i]=mul(pref[i-1],bruk[g[node][i]]);
  }
  for(int i=(int)g[node].size()-1;i>=0;i--){
    if(i==(int)g[node].size()-1) suf[i]=bruk[g[node][i]];
    else suf[i]=mul(suf[i+1],bruk[g[node][i]]);
  }
  for(int i=0;i<(int)g[node].size();i++){
    int ntren=tren;
    if(i>0) ntren=mul(ntren,pref[i-1]);
    if(i<(int)g[node].size()-1) ntren=mul(ntren,suf[i+1]);
    dfs2(g[node][i],ntren);
  }
}

void init(int N,int M, vector<int> P, vector<int> A) {
  n=N; m=M; p=P; a=A;
  for(int i=1;i<n+m;i++) g[p[i]].push_back(i);
  dfs(0);
  dfs2(0,1);
  //for(int i=0;i<m;i++) cout<<power[i]<<" "; cout<<"\n";
  //for(int i=0;i<n+m;i++) cout<<bruk[i]<<" "; cout<<"\n";
}

int count_ways(int L, int R) {
  L-=n;
  R-=n;
  for(int i=L;i<=R;i++) a[i]=!a[i];
  int ret=0;
  for(int i=0;i<m;i++) if(a[i]) ret=add(ret,power[i]);
  return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 4 ms 5200 KB Output is correct
12 Correct 4 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 4944 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 4 ms 5200 KB Output is correct
20 Correct 4 ms 4944 KB Output is correct
21 Correct 3 ms 4944 KB Output is correct
22 Correct 3 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 4944 KB Output is correct
30 Correct 3 ms 4944 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5064 KB Output is correct
33 Correct 4 ms 4944 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 4 ms 4944 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 3 ms 4944 KB Output is correct
42 Correct 4 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3012 ms 7504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3012 ms 7504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 4 ms 5200 KB Output is correct
12 Correct 4 ms 4944 KB Output is correct
13 Execution timed out 3012 ms 7504 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 4944 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 4 ms 5200 KB Output is correct
20 Correct 4 ms 4944 KB Output is correct
21 Correct 3 ms 4944 KB Output is correct
22 Correct 3 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 4944 KB Output is correct
30 Correct 3 ms 4944 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5064 KB Output is correct
33 Correct 4 ms 4944 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 4 ms 4944 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 3 ms 4944 KB Output is correct
42 Correct 4 ms 4944 KB Output is correct
43 Correct 1182 ms 5200 KB Output is correct
44 Correct 1746 ms 5200 KB Output is correct
45 Correct 1791 ms 5200 KB Output is correct
46 Correct 2279 ms 5328 KB Output is correct
47 Correct 2670 ms 5328 KB Output is correct
48 Correct 2527 ms 5380 KB Output is correct
49 Correct 2623 ms 5380 KB Output is correct
50 Correct 2247 ms 5376 KB Output is correct
51 Correct 2686 ms 5220 KB Output is correct
52 Correct 2775 ms 5212 KB Output is correct
53 Correct 903 ms 6256 KB Output is correct
54 Correct 2777 ms 5328 KB Output is correct
55 Correct 2562 ms 5200 KB Output is correct
56 Correct 2773 ms 5200 KB Output is correct
57 Correct 2686 ms 5072 KB Output is correct
58 Correct 2720 ms 6352 KB Output is correct
59 Correct 2698 ms 6448 KB Output is correct
60 Correct 2673 ms 6352 KB Output is correct
61 Correct 1529 ms 5456 KB Output is correct
62 Correct 1762 ms 5200 KB Output is correct
63 Correct 2246 ms 5072 KB Output is correct
64 Correct 2515 ms 5200 KB Output is correct
65 Correct 666 ms 5072 KB Output is correct
66 Correct 2012 ms 5324 KB Output is correct
67 Correct 2292 ms 5200 KB Output is correct
68 Correct 2282 ms 5328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 4944 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 4944 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 4 ms 5200 KB Output is correct
20 Correct 4 ms 4944 KB Output is correct
21 Correct 3 ms 4944 KB Output is correct
22 Correct 3 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 4944 KB Output is correct
30 Correct 3 ms 4944 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5064 KB Output is correct
33 Correct 4 ms 4944 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 4 ms 4944 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 3 ms 4944 KB Output is correct
42 Correct 4 ms 4944 KB Output is correct
43 Execution timed out 3012 ms 7504 KB Time limit exceeded
44 Halted 0 ms 0 KB -