답안 #932890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
932890 2024-02-24T10:58:50 Z PotatoMan Binaria (CCO23_day1problem1) C++14
25 / 25
60 ms 19960 KB
#include <bits/stdc++.h>
#define inf INT_MAX
#define longlonginf LONG_LONG_MAX
#define mod 1000003
#define MAXN 200005
#define pii pair<ll,ll>
#define ll long long
#define deb(x) cerr<<"[ "<<#x<<" = "<<x<<" ]";
#define yes() cout<<"YES\n";
#define no() cout<<"NO\n";
using namespace std;
 
ll n,k,m,q,cur;
ll ans = 0;
string subtask;
int tc = 1;

ll binpow(ll x,ll y){
	if( y == 0 ) return 1;
	ll res = binpow(x,y/2);
	res *= res;
	res %= mod;
	if( y % 2 ) res *= x;
	return res%mod;
}

void solve(){
	cin>>n>>k;
	ll a[n+5];
	ll m = n-k+1;
	for(int i = 0 ; i < m ; i++){
		cin>>a[i];
	}
	int v[n+5];
	for(int i = 0 ; i < n ; i++) v[i] = 2;
	for(int i = m-2 ; i >= 0 ; i--){
		if( a[i] == a[i+1]-1 ) {
			if( v[i+k] == 0 ){
				cout<<0<<"\n";
				return;
			}
			v[i] = 0;
		}
		else if( a[i] == a[i+1]+1 ) {
			if( v[i+k] == 1 ){
				cout<<0<<"\n";
				return;
			}
			v[i] = 1;
		}
		else if( a[i] == a[i+1] ){
			v[i] = v[i+k];
		}
		else if( abs(a[i]-a[i+1]) > 1 ){
			cout<<0<<"\n";
			return;
		} 
	}
	ll x = 0, c = a[0];
	for(int i = 0 ; i < k ; i++){
		if( v[i] == 1 ) c--;
		if( v[i] == 2 ) x++;
	}
	if( x-c < 0 || c < 0 ) {
		cout<<0<<"\n";
		return;
	}
	ll fact[k+5];
	fact[0] = fact[1] = 1;
	for(ll i = 2 ; i <= x ; i++){
		fact[i] = fact[i-1]*i;
		fact[i] %= mod;
	}
	ans = fact[x];
	ll foo = (fact[c]*fact[x-c])%mod;
	ans *= binpow(foo,mod-2);
	cout<<ans%mod<<"\n";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	//cin>>T;
	for(int i = 0 ; i < T ; i++){
		//cout<<"Case #"<<i+1<<": ";
		solve();
		tc++;
	}
	return 0;
}
 
/*
	same val different variable 
	swapped multidimentional size
	out of bound for loop
	(constraint change in loop)
	forget to change bool to int
	misread -> missed subtask
	you thought u declared it huh?
	not i but x
	logical operator
	wrong example/proof
	thoroughly
	wrong variables
	thinking it wrong
	bruh just try some test case
	capitals ;-;
	wrong data structure lol
	count memory usement
	corner case
	oversized array
	orders
	statements
	size initializer
	while con
	map -> array
	wrong digits??
	swapped variables??
	check if theres any variabled
	that got declared twice
	find some pattern
	name collision
	constraints??!
	mod !!
	resets
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 46 ms 13888 KB Output is correct
36 Correct 48 ms 14676 KB Output is correct
37 Correct 52 ms 14928 KB Output is correct
38 Correct 49 ms 14932 KB Output is correct
39 Correct 39 ms 14016 KB Output is correct
40 Correct 47 ms 14908 KB Output is correct
41 Correct 48 ms 14932 KB Output is correct
42 Correct 47 ms 14160 KB Output is correct
43 Correct 43 ms 13908 KB Output is correct
44 Correct 45 ms 13908 KB Output is correct
45 Correct 42 ms 14052 KB Output is correct
46 Correct 41 ms 13912 KB Output is correct
47 Correct 45 ms 14016 KB Output is correct
48 Correct 47 ms 14928 KB Output is correct
49 Correct 46 ms 14932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 46 ms 13888 KB Output is correct
36 Correct 48 ms 14676 KB Output is correct
37 Correct 52 ms 14928 KB Output is correct
38 Correct 49 ms 14932 KB Output is correct
39 Correct 39 ms 14016 KB Output is correct
40 Correct 47 ms 14908 KB Output is correct
41 Correct 48 ms 14932 KB Output is correct
42 Correct 47 ms 14160 KB Output is correct
43 Correct 43 ms 13908 KB Output is correct
44 Correct 45 ms 13908 KB Output is correct
45 Correct 42 ms 14052 KB Output is correct
46 Correct 41 ms 13912 KB Output is correct
47 Correct 45 ms 14016 KB Output is correct
48 Correct 47 ms 14928 KB Output is correct
49 Correct 46 ms 14932 KB Output is correct
50 Correct 58 ms 16944 KB Output is correct
51 Correct 59 ms 16944 KB Output is correct
52 Correct 58 ms 16956 KB Output is correct
53 Correct 60 ms 16944 KB Output is correct
54 Correct 58 ms 16964 KB Output is correct
55 Correct 58 ms 16944 KB Output is correct
56 Correct 58 ms 16964 KB Output is correct
57 Correct 56 ms 16064 KB Output is correct
58 Correct 59 ms 16980 KB Output is correct
59 Correct 58 ms 16976 KB Output is correct
60 Correct 54 ms 16064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 46 ms 13888 KB Output is correct
36 Correct 48 ms 14676 KB Output is correct
37 Correct 52 ms 14928 KB Output is correct
38 Correct 49 ms 14932 KB Output is correct
39 Correct 39 ms 14016 KB Output is correct
40 Correct 47 ms 14908 KB Output is correct
41 Correct 48 ms 14932 KB Output is correct
42 Correct 47 ms 14160 KB Output is correct
43 Correct 43 ms 13908 KB Output is correct
44 Correct 45 ms 13908 KB Output is correct
45 Correct 42 ms 14052 KB Output is correct
46 Correct 41 ms 13912 KB Output is correct
47 Correct 45 ms 14016 KB Output is correct
48 Correct 47 ms 14928 KB Output is correct
49 Correct 46 ms 14932 KB Output is correct
50 Correct 58 ms 16944 KB Output is correct
51 Correct 59 ms 16944 KB Output is correct
52 Correct 58 ms 16956 KB Output is correct
53 Correct 60 ms 16944 KB Output is correct
54 Correct 58 ms 16964 KB Output is correct
55 Correct 58 ms 16944 KB Output is correct
56 Correct 58 ms 16964 KB Output is correct
57 Correct 56 ms 16064 KB Output is correct
58 Correct 59 ms 16980 KB Output is correct
59 Correct 58 ms 16976 KB Output is correct
60 Correct 54 ms 16064 KB Output is correct
61 Correct 18 ms 19800 KB Output is correct
62 Correct 18 ms 19800 KB Output is correct
63 Correct 18 ms 19804 KB Output is correct
64 Correct 17 ms 19804 KB Output is correct
65 Correct 42 ms 19392 KB Output is correct
66 Correct 34 ms 19900 KB Output is correct
67 Correct 58 ms 19024 KB Output is correct
68 Correct 21 ms 19548 KB Output is correct
69 Correct 17 ms 19804 KB Output is correct
70 Correct 17 ms 19804 KB Output is correct
71 Correct 17 ms 19960 KB Output is correct