답안 #938998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938998 2024-03-06T03:12:23 Z irmuun 디지털 회로 (IOI22_circuit) C++17
18 / 100
3000 ms 7208 KB
#include<bits/stdc++.h>
#include "circuit.h"

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

const int mod=1000002022;

const int maxn=2e5;
vector<int>adj[maxn];
vector<int>a;
int n,m;

void init(int N,int M,vector<int>p,vector<int>A){
    n=N;
    m=M;
    a=A;
    for(int i=1;i<n+m;i++){
        adj[p[i]].pb(i);
    }
}

int count_ways(int l,int r){
    if(n==1){
        l-=n;
        r-=n;
        int cnt=0;
        for(int i=0;i<m;i++){
            if(l<=i&&i<=r){
                a[i]=1-a[i];
            }
            cnt+=a[i];
        }
        return cnt;
    }
    l-=n;
    r-=n;
    for(int i=l;i<=r;i++){
        a[i]=1-a[i];
    }
    int ans=0;
    int cnt[n+m+5][2];//number of ways end with 0/1
    for(int j=n;j<n+m;j++){
        cnt[j][a[j-n]]=1;
        cnt[j][1-a[j-n]]=0;
    }
    for(int i=n-1;i>=0;i--){
        int sz=adj[i].size();
        int dp[sz+2];
        fill(dp,dp+sz+1,0);
        dp[0]=1;
        int cur=0;
        for(int x:adj[i]){
            cur++;
            for(int j=cur-1;j>=0;j--){
                dp[j+1]+=1ll*dp[j]*cnt[x][1]%mod;
                dp[j+1]%=mod;
                dp[j]=1ll*dp[j]*cnt[x][0]%mod;
                dp[j]%=mod;
            }
        }
        int c1=0,c0=0;
        for(int j=0;j<=cur;j++){
            c0+=dp[j];
            c0%=mod;
        }
        cnt[i][0]=0;
        cnt[i][1]=0;
        for(int j=cur;j>=1;j--){
            c1=(c1+dp[j])%mod;
            c0=(c0-dp[j]+mod)%mod;
            cnt[i][1]+=c1;
            cnt[i][1]%=mod;
            cnt[i][0]+=c0;
            cnt[i][0]%=mod;
        }
    }
    return cnt[0][1];
}

Compilation message

circuit.cpp: In function 'int count_ways(int, int)':
circuit.cpp:47:9: warning: unused variable 'ans' [-Wunused-variable]
   47 |     int ans=0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4952 KB Output is correct
5 Correct 1 ms 4952 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4952 KB Output is correct
8 Correct 1 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4996 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4952 KB Output is correct
5 Correct 2 ms 4952 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 2 ms 4952 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4952 KB Output is correct
5 Correct 1 ms 4952 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4952 KB Output is correct
8 Correct 1 ms 4952 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 1 ms 4996 KB Output is correct
11 Correct 1 ms 4952 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 1 ms 4952 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 2 ms 4952 KB Output is correct
21 Correct 2 ms 4952 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 2 ms 4952 KB Output is correct
24 Correct 2 ms 5204 KB Output is correct
25 Correct 2 ms 4952 KB Output is correct
26 Correct 2 ms 4952 KB Output is correct
27 Correct 2 ms 5208 KB Output is correct
28 Correct 2 ms 4952 KB Output is correct
29 Correct 1 ms 5108 KB Output is correct
30 Correct 2 ms 5148 KB Output is correct
31 Correct 2 ms 4952 KB Output is correct
32 Correct 2 ms 4952 KB Output is correct
33 Correct 2 ms 4952 KB Output is correct
34 Correct 2 ms 4952 KB Output is correct
35 Correct 3 ms 4964 KB Output is correct
36 Correct 2 ms 4952 KB Output is correct
37 Correct 11 ms 5208 KB Output is correct
38 Correct 11 ms 5208 KB Output is correct
39 Correct 1 ms 4952 KB Output is correct
40 Correct 2 ms 4952 KB Output is correct
41 Correct 2 ms 4952 KB Output is correct
42 Correct 2 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3027 ms 7208 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3027 ms 7208 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4996 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4952 KB Output is correct
5 Correct 2 ms 4952 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 2 ms 4952 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
13 Execution timed out 3027 ms 7208 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4952 KB Output is correct
5 Correct 1 ms 4952 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4952 KB Output is correct
8 Correct 1 ms 4952 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 1 ms 4996 KB Output is correct
11 Correct 1 ms 4952 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 1 ms 4952 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 2 ms 4952 KB Output is correct
21 Correct 2 ms 4952 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 2 ms 4952 KB Output is correct
24 Correct 2 ms 5204 KB Output is correct
25 Correct 2 ms 4952 KB Output is correct
26 Correct 2 ms 4952 KB Output is correct
27 Correct 2 ms 5208 KB Output is correct
28 Correct 2 ms 4952 KB Output is correct
29 Correct 1 ms 5108 KB Output is correct
30 Correct 2 ms 5148 KB Output is correct
31 Correct 2 ms 4952 KB Output is correct
32 Correct 2 ms 4952 KB Output is correct
33 Correct 2 ms 4952 KB Output is correct
34 Correct 2 ms 4952 KB Output is correct
35 Correct 3 ms 4964 KB Output is correct
36 Correct 2 ms 4952 KB Output is correct
37 Correct 11 ms 5208 KB Output is correct
38 Correct 11 ms 5208 KB Output is correct
39 Correct 1 ms 4952 KB Output is correct
40 Correct 2 ms 4952 KB Output is correct
41 Correct 2 ms 4952 KB Output is correct
42 Correct 2 ms 4952 KB Output is correct
43 Execution timed out 3058 ms 5208 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 1 ms 4952 KB Output is correct
5 Correct 1 ms 4952 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4952 KB Output is correct
8 Correct 1 ms 4952 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 1 ms 4996 KB Output is correct
11 Correct 1 ms 4952 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 1 ms 4952 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 2 ms 4952 KB Output is correct
21 Correct 2 ms 4952 KB Output is correct
22 Correct 2 ms 4952 KB Output is correct
23 Correct 2 ms 4952 KB Output is correct
24 Correct 2 ms 5204 KB Output is correct
25 Correct 2 ms 4952 KB Output is correct
26 Correct 2 ms 4952 KB Output is correct
27 Correct 2 ms 5208 KB Output is correct
28 Correct 2 ms 4952 KB Output is correct
29 Correct 1 ms 5108 KB Output is correct
30 Correct 2 ms 5148 KB Output is correct
31 Correct 2 ms 4952 KB Output is correct
32 Correct 2 ms 4952 KB Output is correct
33 Correct 2 ms 4952 KB Output is correct
34 Correct 2 ms 4952 KB Output is correct
35 Correct 3 ms 4964 KB Output is correct
36 Correct 2 ms 4952 KB Output is correct
37 Correct 11 ms 5208 KB Output is correct
38 Correct 11 ms 5208 KB Output is correct
39 Correct 1 ms 4952 KB Output is correct
40 Correct 2 ms 4952 KB Output is correct
41 Correct 2 ms 4952 KB Output is correct
42 Correct 2 ms 4952 KB Output is correct
43 Execution timed out 3027 ms 7208 KB Time limit exceeded
44 Halted 0 ms 0 KB -