답안 #988309

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988309 2024-05-24T13:05:08 Z Abdalaziz_Alshami Binaria (CCO23_day1problem1) C++17
25 / 25
87 ms 36556 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+1,mod=1e6+3;
int fac[N+1],ifac[N+1],a[N+1];
int pxp(int x,int p)
{
	if(!p) return 1;
	if(p&1) return (x*pxp(x,p-1)%mod)%mod;
	int ret=pxp(x,p/2);
	return (ret*ret)%mod;
}
signed main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	fac[0]=1;
	for(int i=1;i<N;i++) fac[i]=(fac[i-1]*i)%mod;
	ifac[N-1]=pxp(fac[N-1],mod-2);
	for(int i=N-2;i>=0;i--) ifac[i]=(ifac[i+1]*(i+1))%mod;
	
	
	int n,k; cin>>n>>k;
	int b[n-k+1]; for(int i=0;i<n-k+1;i++) cin>>b[i];
	memset(a,-1,sizeof a);
	bool f=false;
	for(int i=0;i<n-k;i++){
		if(a[i]==-1){
			if(b[i]>b[i+1]) a[i]=1,a[i+k]=0;
			else if(b[i]<b[i+1]) a[i]=0,a[i+k]=1;
		}
		else if(a[i]==1){
			if(b[i]==b[i+1]) a[i+k]=a[i];
			else if(b[i]>b[i+1]) a[i+k]=0;
			else f=true;
		}
		else {
			if(b[i]==b[i+1]) a[i+k]=a[i];
			else if(b[i]<b[i+1]) a[i+k]=1;
			else f=true;
		}
	}
	for(int i=n-k-1;i>=0;i--){
		if(a[i+k]==1){
			if(b[i]==b[i+1]) a[i]=1;
			else if(b[i]<b[i+1]) a[i]=0;
		}
		else if(a[i+k]==0){
			if(b[i]==b[i+1]) a[i]=0;
			else if(b[i]<b[i+1]) a[i]=1;
		}
	}
	int s=0;
	for(int i=0;i<k;i++){
		if(a[i]==-1) s++;
		else if(a[i]) b[0]--;
	}
	if(f) { cout<<0<<endl; return 0; }
	if(s==b[0]) { cout<<1<<endl; return 0; } 
	if(s<b[0]) { cout<<0<<endl; return 0; }
	int x=ifac[b[0]]*ifac[s-b[0]];
	x*=fac[s];
	cout<<x%mod<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23896 KB Output is correct
2 Correct 18 ms 23900 KB Output is correct
3 Correct 18 ms 23892 KB Output is correct
4 Correct 18 ms 23748 KB Output is correct
5 Correct 18 ms 23900 KB Output is correct
6 Correct 18 ms 23900 KB Output is correct
7 Correct 18 ms 23724 KB Output is correct
8 Correct 18 ms 23764 KB Output is correct
9 Correct 18 ms 23900 KB Output is correct
10 Correct 19 ms 23888 KB Output is correct
11 Correct 18 ms 23900 KB Output is correct
12 Correct 18 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23896 KB Output is correct
2 Correct 18 ms 23900 KB Output is correct
3 Correct 18 ms 23892 KB Output is correct
4 Correct 18 ms 23748 KB Output is correct
5 Correct 18 ms 23900 KB Output is correct
6 Correct 18 ms 23900 KB Output is correct
7 Correct 18 ms 23724 KB Output is correct
8 Correct 18 ms 23764 KB Output is correct
9 Correct 18 ms 23900 KB Output is correct
10 Correct 19 ms 23888 KB Output is correct
11 Correct 18 ms 23900 KB Output is correct
12 Correct 18 ms 23900 KB Output is correct
13 Correct 18 ms 23900 KB Output is correct
14 Correct 18 ms 23900 KB Output is correct
15 Correct 18 ms 23900 KB Output is correct
16 Correct 18 ms 23748 KB Output is correct
17 Correct 18 ms 23900 KB Output is correct
18 Correct 21 ms 23892 KB Output is correct
19 Correct 18 ms 23896 KB Output is correct
20 Correct 18 ms 23900 KB Output is correct
21 Correct 18 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23896 KB Output is correct
2 Correct 18 ms 23900 KB Output is correct
3 Correct 18 ms 23892 KB Output is correct
4 Correct 18 ms 23748 KB Output is correct
5 Correct 18 ms 23900 KB Output is correct
6 Correct 18 ms 23900 KB Output is correct
7 Correct 18 ms 23724 KB Output is correct
8 Correct 18 ms 23764 KB Output is correct
9 Correct 18 ms 23900 KB Output is correct
10 Correct 19 ms 23888 KB Output is correct
11 Correct 18 ms 23900 KB Output is correct
12 Correct 18 ms 23900 KB Output is correct
13 Correct 18 ms 23900 KB Output is correct
14 Correct 18 ms 23900 KB Output is correct
15 Correct 18 ms 23900 KB Output is correct
16 Correct 18 ms 23748 KB Output is correct
17 Correct 18 ms 23900 KB Output is correct
18 Correct 21 ms 23892 KB Output is correct
19 Correct 18 ms 23896 KB Output is correct
20 Correct 18 ms 23900 KB Output is correct
21 Correct 18 ms 23900 KB Output is correct
22 Correct 19 ms 23900 KB Output is correct
23 Correct 18 ms 23896 KB Output is correct
24 Correct 18 ms 23900 KB Output is correct
25 Correct 18 ms 23936 KB Output is correct
26 Correct 18 ms 23896 KB Output is correct
27 Correct 18 ms 23900 KB Output is correct
28 Correct 18 ms 23896 KB Output is correct
29 Correct 18 ms 23900 KB Output is correct
30 Correct 18 ms 23888 KB Output is correct
31 Correct 18 ms 23896 KB Output is correct
32 Correct 18 ms 23900 KB Output is correct
33 Correct 18 ms 23764 KB Output is correct
34 Correct 18 ms 23920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23896 KB Output is correct
2 Correct 18 ms 23900 KB Output is correct
3 Correct 18 ms 23892 KB Output is correct
4 Correct 18 ms 23748 KB Output is correct
5 Correct 18 ms 23900 KB Output is correct
6 Correct 18 ms 23900 KB Output is correct
7 Correct 18 ms 23724 KB Output is correct
8 Correct 18 ms 23764 KB Output is correct
9 Correct 18 ms 23900 KB Output is correct
10 Correct 19 ms 23888 KB Output is correct
11 Correct 18 ms 23900 KB Output is correct
12 Correct 18 ms 23900 KB Output is correct
13 Correct 18 ms 23900 KB Output is correct
14 Correct 18 ms 23900 KB Output is correct
15 Correct 18 ms 23900 KB Output is correct
16 Correct 18 ms 23748 KB Output is correct
17 Correct 18 ms 23900 KB Output is correct
18 Correct 21 ms 23892 KB Output is correct
19 Correct 18 ms 23896 KB Output is correct
20 Correct 18 ms 23900 KB Output is correct
21 Correct 18 ms 23900 KB Output is correct
22 Correct 19 ms 23900 KB Output is correct
23 Correct 18 ms 23896 KB Output is correct
24 Correct 18 ms 23900 KB Output is correct
25 Correct 18 ms 23936 KB Output is correct
26 Correct 18 ms 23896 KB Output is correct
27 Correct 18 ms 23900 KB Output is correct
28 Correct 18 ms 23896 KB Output is correct
29 Correct 18 ms 23900 KB Output is correct
30 Correct 18 ms 23888 KB Output is correct
31 Correct 18 ms 23896 KB Output is correct
32 Correct 18 ms 23900 KB Output is correct
33 Correct 18 ms 23764 KB Output is correct
34 Correct 18 ms 23920 KB Output is correct
35 Correct 65 ms 33696 KB Output is correct
36 Correct 75 ms 34128 KB Output is correct
37 Correct 69 ms 34632 KB Output is correct
38 Correct 67 ms 34644 KB Output is correct
39 Correct 65 ms 33620 KB Output is correct
40 Correct 70 ms 34612 KB Output is correct
41 Correct 70 ms 34496 KB Output is correct
42 Correct 63 ms 33620 KB Output is correct
43 Correct 68 ms 33616 KB Output is correct
44 Correct 61 ms 33616 KB Output is correct
45 Correct 61 ms 33620 KB Output is correct
46 Correct 61 ms 33616 KB Output is correct
47 Correct 63 ms 33616 KB Output is correct
48 Correct 66 ms 34640 KB Output is correct
49 Correct 66 ms 34644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23896 KB Output is correct
2 Correct 18 ms 23900 KB Output is correct
3 Correct 18 ms 23892 KB Output is correct
4 Correct 18 ms 23748 KB Output is correct
5 Correct 18 ms 23900 KB Output is correct
6 Correct 18 ms 23900 KB Output is correct
7 Correct 18 ms 23724 KB Output is correct
8 Correct 18 ms 23764 KB Output is correct
9 Correct 18 ms 23900 KB Output is correct
10 Correct 19 ms 23888 KB Output is correct
11 Correct 18 ms 23900 KB Output is correct
12 Correct 18 ms 23900 KB Output is correct
13 Correct 18 ms 23900 KB Output is correct
14 Correct 18 ms 23900 KB Output is correct
15 Correct 18 ms 23900 KB Output is correct
16 Correct 18 ms 23748 KB Output is correct
17 Correct 18 ms 23900 KB Output is correct
18 Correct 21 ms 23892 KB Output is correct
19 Correct 18 ms 23896 KB Output is correct
20 Correct 18 ms 23900 KB Output is correct
21 Correct 18 ms 23900 KB Output is correct
22 Correct 19 ms 23900 KB Output is correct
23 Correct 18 ms 23896 KB Output is correct
24 Correct 18 ms 23900 KB Output is correct
25 Correct 18 ms 23936 KB Output is correct
26 Correct 18 ms 23896 KB Output is correct
27 Correct 18 ms 23900 KB Output is correct
28 Correct 18 ms 23896 KB Output is correct
29 Correct 18 ms 23900 KB Output is correct
30 Correct 18 ms 23888 KB Output is correct
31 Correct 18 ms 23896 KB Output is correct
32 Correct 18 ms 23900 KB Output is correct
33 Correct 18 ms 23764 KB Output is correct
34 Correct 18 ms 23920 KB Output is correct
35 Correct 65 ms 33696 KB Output is correct
36 Correct 75 ms 34128 KB Output is correct
37 Correct 69 ms 34632 KB Output is correct
38 Correct 67 ms 34644 KB Output is correct
39 Correct 65 ms 33620 KB Output is correct
40 Correct 70 ms 34612 KB Output is correct
41 Correct 70 ms 34496 KB Output is correct
42 Correct 63 ms 33620 KB Output is correct
43 Correct 68 ms 33616 KB Output is correct
44 Correct 61 ms 33616 KB Output is correct
45 Correct 61 ms 33620 KB Output is correct
46 Correct 61 ms 33616 KB Output is correct
47 Correct 63 ms 33616 KB Output is correct
48 Correct 66 ms 34640 KB Output is correct
49 Correct 66 ms 34644 KB Output is correct
50 Correct 76 ms 36556 KB Output is correct
51 Correct 81 ms 36376 KB Output is correct
52 Correct 83 ms 36436 KB Output is correct
53 Correct 87 ms 36380 KB Output is correct
54 Correct 78 ms 36432 KB Output is correct
55 Correct 76 ms 36552 KB Output is correct
56 Correct 77 ms 36380 KB Output is correct
57 Correct 81 ms 35608 KB Output is correct
58 Correct 84 ms 36436 KB Output is correct
59 Correct 76 ms 36444 KB Output is correct
60 Correct 80 ms 35876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23896 KB Output is correct
2 Correct 18 ms 23900 KB Output is correct
3 Correct 18 ms 23892 KB Output is correct
4 Correct 18 ms 23748 KB Output is correct
5 Correct 18 ms 23900 KB Output is correct
6 Correct 18 ms 23900 KB Output is correct
7 Correct 18 ms 23724 KB Output is correct
8 Correct 18 ms 23764 KB Output is correct
9 Correct 18 ms 23900 KB Output is correct
10 Correct 19 ms 23888 KB Output is correct
11 Correct 18 ms 23900 KB Output is correct
12 Correct 18 ms 23900 KB Output is correct
13 Correct 18 ms 23900 KB Output is correct
14 Correct 18 ms 23900 KB Output is correct
15 Correct 18 ms 23900 KB Output is correct
16 Correct 18 ms 23748 KB Output is correct
17 Correct 18 ms 23900 KB Output is correct
18 Correct 21 ms 23892 KB Output is correct
19 Correct 18 ms 23896 KB Output is correct
20 Correct 18 ms 23900 KB Output is correct
21 Correct 18 ms 23900 KB Output is correct
22 Correct 19 ms 23900 KB Output is correct
23 Correct 18 ms 23896 KB Output is correct
24 Correct 18 ms 23900 KB Output is correct
25 Correct 18 ms 23936 KB Output is correct
26 Correct 18 ms 23896 KB Output is correct
27 Correct 18 ms 23900 KB Output is correct
28 Correct 18 ms 23896 KB Output is correct
29 Correct 18 ms 23900 KB Output is correct
30 Correct 18 ms 23888 KB Output is correct
31 Correct 18 ms 23896 KB Output is correct
32 Correct 18 ms 23900 KB Output is correct
33 Correct 18 ms 23764 KB Output is correct
34 Correct 18 ms 23920 KB Output is correct
35 Correct 65 ms 33696 KB Output is correct
36 Correct 75 ms 34128 KB Output is correct
37 Correct 69 ms 34632 KB Output is correct
38 Correct 67 ms 34644 KB Output is correct
39 Correct 65 ms 33620 KB Output is correct
40 Correct 70 ms 34612 KB Output is correct
41 Correct 70 ms 34496 KB Output is correct
42 Correct 63 ms 33620 KB Output is correct
43 Correct 68 ms 33616 KB Output is correct
44 Correct 61 ms 33616 KB Output is correct
45 Correct 61 ms 33620 KB Output is correct
46 Correct 61 ms 33616 KB Output is correct
47 Correct 63 ms 33616 KB Output is correct
48 Correct 66 ms 34640 KB Output is correct
49 Correct 66 ms 34644 KB Output is correct
50 Correct 76 ms 36556 KB Output is correct
51 Correct 81 ms 36376 KB Output is correct
52 Correct 83 ms 36436 KB Output is correct
53 Correct 87 ms 36380 KB Output is correct
54 Correct 78 ms 36432 KB Output is correct
55 Correct 76 ms 36552 KB Output is correct
56 Correct 77 ms 36380 KB Output is correct
57 Correct 81 ms 35608 KB Output is correct
58 Correct 84 ms 36436 KB Output is correct
59 Correct 76 ms 36444 KB Output is correct
60 Correct 80 ms 35876 KB Output is correct
61 Correct 20 ms 23900 KB Output is correct
62 Correct 19 ms 23900 KB Output is correct
63 Correct 19 ms 23900 KB Output is correct
64 Correct 19 ms 23900 KB Output is correct
65 Correct 53 ms 31096 KB Output is correct
66 Correct 43 ms 28856 KB Output is correct
67 Correct 81 ms 35412 KB Output is correct
68 Correct 25 ms 24912 KB Output is correct
69 Correct 19 ms 23896 KB Output is correct
70 Correct 19 ms 23900 KB Output is correct
71 Correct 20 ms 23900 KB Output is correct