답안 #1027459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027459 2024-07-19T06:43:19 Z cnn008 Binaria (CCO23_day1problem1) C++17
25 / 25
181 ms 36616 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef N_N_C
#include "debug.h"
#else
#define cebug(...) "Arya"
#endif

#define int long long

const int N=1e6+5;
const int mod=1e6+3;

int n,k,a[N],f[N],inv[N],b[N];
int powmod(int a, int k, int m){
   	int ans=1;
    while(k){
        if(k&1) ans=(ans*a)%m;
        a=(a*a)%m;
        k/=2;
    }
    return ans;
}
int C(int n, int k){
	if(n<k || k<0) return 0;
	return f[n]*inv[k]%mod*inv[n-k]%mod;
}
void sol(){
	cin>>n>>k;
	for(int i=k; i<=n; i++) cin>>a[i];
	memset(b,-1,sizeof(b));
	for(int i=k+1; i<=n; i++){
		if(a[i]==a[i-1]+1){
			if(b[i-k]==1){
				cout<<"0";
				return;
			}
			b[i-k]=0;
			b[i]=1;
		}else if(a[i]==a[i-1]){
			if(b[i-k]==1) b[i]=1;
			if(b[i-k]==0) b[i]=0;
			
		}else if(a[i]==a[i-1]-1){
			if(b[i-k]==0){
				cout<<"0";
				return;
			}
			b[i-k]=1;
			b[i]=0;
		}else{
			cout<<"0";
			return;
		}
	}
	for(int i=n; i>=k+1; i--) if(a[i]==a[i-1]) b[i]=b[i-k]=max(b[i],b[i-k]);
	int sz=0,cnt=0;
	for(int i=1; i<=k; i++){
		if(b[i]==-1) sz++;
		if(b[i]==1) cnt++;
	}
	cout<<C(sz,a[k]-cnt);
}
signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen(".inp", "r", stdin);
    // freopen(".out", "w", stdout);
    f[0]=1;
    for(int i=1; i<N; i++) f[i]=(f[i-1]*i)%mod;
    inv[0]=1;
    for(int i=1; i<N; i++) inv[i]=powmod(f[i],mod-2,mod);
    int tt=1;
    //cin>>tt; 
    while(tt--){
    	sol();
    }
    cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 23892 KB Output is correct
2 Correct 109 ms 23888 KB Output is correct
3 Correct 109 ms 23856 KB Output is correct
4 Correct 112 ms 23932 KB Output is correct
5 Correct 112 ms 23888 KB Output is correct
6 Correct 109 ms 23888 KB Output is correct
7 Correct 111 ms 23960 KB Output is correct
8 Correct 107 ms 23888 KB Output is correct
9 Correct 109 ms 23684 KB Output is correct
10 Correct 111 ms 23904 KB Output is correct
11 Correct 115 ms 23980 KB Output is correct
12 Correct 111 ms 23892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 23892 KB Output is correct
2 Correct 109 ms 23888 KB Output is correct
3 Correct 109 ms 23856 KB Output is correct
4 Correct 112 ms 23932 KB Output is correct
5 Correct 112 ms 23888 KB Output is correct
6 Correct 109 ms 23888 KB Output is correct
7 Correct 111 ms 23960 KB Output is correct
8 Correct 107 ms 23888 KB Output is correct
9 Correct 109 ms 23684 KB Output is correct
10 Correct 111 ms 23904 KB Output is correct
11 Correct 115 ms 23980 KB Output is correct
12 Correct 111 ms 23892 KB Output is correct
13 Correct 106 ms 23892 KB Output is correct
14 Correct 110 ms 23996 KB Output is correct
15 Correct 108 ms 23740 KB Output is correct
16 Correct 110 ms 23832 KB Output is correct
17 Correct 113 ms 23696 KB Output is correct
18 Correct 110 ms 23752 KB Output is correct
19 Correct 108 ms 23892 KB Output is correct
20 Correct 110 ms 23888 KB Output is correct
21 Correct 107 ms 23892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 23892 KB Output is correct
2 Correct 109 ms 23888 KB Output is correct
3 Correct 109 ms 23856 KB Output is correct
4 Correct 112 ms 23932 KB Output is correct
5 Correct 112 ms 23888 KB Output is correct
6 Correct 109 ms 23888 KB Output is correct
7 Correct 111 ms 23960 KB Output is correct
8 Correct 107 ms 23888 KB Output is correct
9 Correct 109 ms 23684 KB Output is correct
10 Correct 111 ms 23904 KB Output is correct
11 Correct 115 ms 23980 KB Output is correct
12 Correct 111 ms 23892 KB Output is correct
13 Correct 106 ms 23892 KB Output is correct
14 Correct 110 ms 23996 KB Output is correct
15 Correct 108 ms 23740 KB Output is correct
16 Correct 110 ms 23832 KB Output is correct
17 Correct 113 ms 23696 KB Output is correct
18 Correct 110 ms 23752 KB Output is correct
19 Correct 108 ms 23892 KB Output is correct
20 Correct 110 ms 23888 KB Output is correct
21 Correct 107 ms 23892 KB Output is correct
22 Correct 109 ms 23780 KB Output is correct
23 Correct 108 ms 23888 KB Output is correct
24 Correct 112 ms 23904 KB Output is correct
25 Correct 114 ms 23876 KB Output is correct
26 Correct 109 ms 23692 KB Output is correct
27 Correct 108 ms 23892 KB Output is correct
28 Correct 111 ms 23928 KB Output is correct
29 Correct 108 ms 23892 KB Output is correct
30 Correct 109 ms 23888 KB Output is correct
31 Correct 112 ms 23892 KB Output is correct
32 Correct 111 ms 24124 KB Output is correct
33 Correct 108 ms 23888 KB Output is correct
34 Correct 109 ms 23888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 23892 KB Output is correct
2 Correct 109 ms 23888 KB Output is correct
3 Correct 109 ms 23856 KB Output is correct
4 Correct 112 ms 23932 KB Output is correct
5 Correct 112 ms 23888 KB Output is correct
6 Correct 109 ms 23888 KB Output is correct
7 Correct 111 ms 23960 KB Output is correct
8 Correct 107 ms 23888 KB Output is correct
9 Correct 109 ms 23684 KB Output is correct
10 Correct 111 ms 23904 KB Output is correct
11 Correct 115 ms 23980 KB Output is correct
12 Correct 111 ms 23892 KB Output is correct
13 Correct 106 ms 23892 KB Output is correct
14 Correct 110 ms 23996 KB Output is correct
15 Correct 108 ms 23740 KB Output is correct
16 Correct 110 ms 23832 KB Output is correct
17 Correct 113 ms 23696 KB Output is correct
18 Correct 110 ms 23752 KB Output is correct
19 Correct 108 ms 23892 KB Output is correct
20 Correct 110 ms 23888 KB Output is correct
21 Correct 107 ms 23892 KB Output is correct
22 Correct 109 ms 23780 KB Output is correct
23 Correct 108 ms 23888 KB Output is correct
24 Correct 112 ms 23904 KB Output is correct
25 Correct 114 ms 23876 KB Output is correct
26 Correct 109 ms 23692 KB Output is correct
27 Correct 108 ms 23892 KB Output is correct
28 Correct 111 ms 23928 KB Output is correct
29 Correct 108 ms 23892 KB Output is correct
30 Correct 109 ms 23888 KB Output is correct
31 Correct 112 ms 23892 KB Output is correct
32 Correct 111 ms 24124 KB Output is correct
33 Correct 108 ms 23888 KB Output is correct
34 Correct 109 ms 23888 KB Output is correct
35 Correct 152 ms 33600 KB Output is correct
36 Correct 153 ms 34132 KB Output is correct
37 Correct 169 ms 34620 KB Output is correct
38 Correct 152 ms 34640 KB Output is correct
39 Correct 147 ms 33676 KB Output is correct
40 Correct 150 ms 34640 KB Output is correct
41 Correct 149 ms 34640 KB Output is correct
42 Correct 153 ms 33584 KB Output is correct
43 Correct 152 ms 33628 KB Output is correct
44 Correct 148 ms 33620 KB Output is correct
45 Correct 150 ms 33616 KB Output is correct
46 Correct 150 ms 33620 KB Output is correct
47 Correct 149 ms 33620 KB Output is correct
48 Correct 150 ms 34640 KB Output is correct
49 Correct 151 ms 35024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 23892 KB Output is correct
2 Correct 109 ms 23888 KB Output is correct
3 Correct 109 ms 23856 KB Output is correct
4 Correct 112 ms 23932 KB Output is correct
5 Correct 112 ms 23888 KB Output is correct
6 Correct 109 ms 23888 KB Output is correct
7 Correct 111 ms 23960 KB Output is correct
8 Correct 107 ms 23888 KB Output is correct
9 Correct 109 ms 23684 KB Output is correct
10 Correct 111 ms 23904 KB Output is correct
11 Correct 115 ms 23980 KB Output is correct
12 Correct 111 ms 23892 KB Output is correct
13 Correct 106 ms 23892 KB Output is correct
14 Correct 110 ms 23996 KB Output is correct
15 Correct 108 ms 23740 KB Output is correct
16 Correct 110 ms 23832 KB Output is correct
17 Correct 113 ms 23696 KB Output is correct
18 Correct 110 ms 23752 KB Output is correct
19 Correct 108 ms 23892 KB Output is correct
20 Correct 110 ms 23888 KB Output is correct
21 Correct 107 ms 23892 KB Output is correct
22 Correct 109 ms 23780 KB Output is correct
23 Correct 108 ms 23888 KB Output is correct
24 Correct 112 ms 23904 KB Output is correct
25 Correct 114 ms 23876 KB Output is correct
26 Correct 109 ms 23692 KB Output is correct
27 Correct 108 ms 23892 KB Output is correct
28 Correct 111 ms 23928 KB Output is correct
29 Correct 108 ms 23892 KB Output is correct
30 Correct 109 ms 23888 KB Output is correct
31 Correct 112 ms 23892 KB Output is correct
32 Correct 111 ms 24124 KB Output is correct
33 Correct 108 ms 23888 KB Output is correct
34 Correct 109 ms 23888 KB Output is correct
35 Correct 152 ms 33600 KB Output is correct
36 Correct 153 ms 34132 KB Output is correct
37 Correct 169 ms 34620 KB Output is correct
38 Correct 152 ms 34640 KB Output is correct
39 Correct 147 ms 33676 KB Output is correct
40 Correct 150 ms 34640 KB Output is correct
41 Correct 149 ms 34640 KB Output is correct
42 Correct 153 ms 33584 KB Output is correct
43 Correct 152 ms 33628 KB Output is correct
44 Correct 148 ms 33620 KB Output is correct
45 Correct 150 ms 33616 KB Output is correct
46 Correct 150 ms 33620 KB Output is correct
47 Correct 149 ms 33620 KB Output is correct
48 Correct 150 ms 34640 KB Output is correct
49 Correct 151 ms 35024 KB Output is correct
50 Correct 161 ms 36432 KB Output is correct
51 Correct 161 ms 36436 KB Output is correct
52 Correct 181 ms 36616 KB Output is correct
53 Correct 169 ms 36436 KB Output is correct
54 Correct 158 ms 36532 KB Output is correct
55 Correct 164 ms 36368 KB Output is correct
56 Correct 164 ms 36496 KB Output is correct
57 Correct 176 ms 35412 KB Output is correct
58 Correct 161 ms 36436 KB Output is correct
59 Correct 168 ms 36476 KB Output is correct
60 Correct 159 ms 35472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 23892 KB Output is correct
2 Correct 109 ms 23888 KB Output is correct
3 Correct 109 ms 23856 KB Output is correct
4 Correct 112 ms 23932 KB Output is correct
5 Correct 112 ms 23888 KB Output is correct
6 Correct 109 ms 23888 KB Output is correct
7 Correct 111 ms 23960 KB Output is correct
8 Correct 107 ms 23888 KB Output is correct
9 Correct 109 ms 23684 KB Output is correct
10 Correct 111 ms 23904 KB Output is correct
11 Correct 115 ms 23980 KB Output is correct
12 Correct 111 ms 23892 KB Output is correct
13 Correct 106 ms 23892 KB Output is correct
14 Correct 110 ms 23996 KB Output is correct
15 Correct 108 ms 23740 KB Output is correct
16 Correct 110 ms 23832 KB Output is correct
17 Correct 113 ms 23696 KB Output is correct
18 Correct 110 ms 23752 KB Output is correct
19 Correct 108 ms 23892 KB Output is correct
20 Correct 110 ms 23888 KB Output is correct
21 Correct 107 ms 23892 KB Output is correct
22 Correct 109 ms 23780 KB Output is correct
23 Correct 108 ms 23888 KB Output is correct
24 Correct 112 ms 23904 KB Output is correct
25 Correct 114 ms 23876 KB Output is correct
26 Correct 109 ms 23692 KB Output is correct
27 Correct 108 ms 23892 KB Output is correct
28 Correct 111 ms 23928 KB Output is correct
29 Correct 108 ms 23892 KB Output is correct
30 Correct 109 ms 23888 KB Output is correct
31 Correct 112 ms 23892 KB Output is correct
32 Correct 111 ms 24124 KB Output is correct
33 Correct 108 ms 23888 KB Output is correct
34 Correct 109 ms 23888 KB Output is correct
35 Correct 152 ms 33600 KB Output is correct
36 Correct 153 ms 34132 KB Output is correct
37 Correct 169 ms 34620 KB Output is correct
38 Correct 152 ms 34640 KB Output is correct
39 Correct 147 ms 33676 KB Output is correct
40 Correct 150 ms 34640 KB Output is correct
41 Correct 149 ms 34640 KB Output is correct
42 Correct 153 ms 33584 KB Output is correct
43 Correct 152 ms 33628 KB Output is correct
44 Correct 148 ms 33620 KB Output is correct
45 Correct 150 ms 33616 KB Output is correct
46 Correct 150 ms 33620 KB Output is correct
47 Correct 149 ms 33620 KB Output is correct
48 Correct 150 ms 34640 KB Output is correct
49 Correct 151 ms 35024 KB Output is correct
50 Correct 161 ms 36432 KB Output is correct
51 Correct 161 ms 36436 KB Output is correct
52 Correct 181 ms 36616 KB Output is correct
53 Correct 169 ms 36436 KB Output is correct
54 Correct 158 ms 36532 KB Output is correct
55 Correct 164 ms 36368 KB Output is correct
56 Correct 164 ms 36496 KB Output is correct
57 Correct 176 ms 35412 KB Output is correct
58 Correct 161 ms 36436 KB Output is correct
59 Correct 168 ms 36476 KB Output is correct
60 Correct 159 ms 35472 KB Output is correct
61 Correct 98 ms 23828 KB Output is correct
62 Correct 95 ms 23896 KB Output is correct
63 Correct 112 ms 23912 KB Output is correct
64 Correct 108 ms 23888 KB Output is correct
65 Correct 143 ms 31128 KB Output is correct
66 Correct 131 ms 28756 KB Output is correct
67 Correct 161 ms 35664 KB Output is correct
68 Correct 115 ms 24916 KB Output is correct
69 Correct 109 ms 23892 KB Output is correct
70 Correct 106 ms 23892 KB Output is correct
71 Correct 112 ms 23892 KB Output is correct