Submission #967987

# Submission time Handle Problem Language Result Execution time Memory
967987 2024-04-23T06:33:51 Z willychan Binaria (CCO23_day1problem1) C++17
25 / 25
77 ms 25172 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
const int MOD = 1e6+3;

struct dsu{
	vector<int> arr;
	int n;
	void init(int _n){
		 n = _n;	
		 arr.resize(n);
		 for(int i=0;i<n;i++) arr[i]=i;
	}
	int query(int a){
		if(arr[a]==a) return a;
		arr[a] = query(arr[a]);
		return arr[a];
	}
	void join(int a,int b){
		a = query(a);
		b = query(b);
		if(a!=b) arr[a]=b;
	}
};

vector<int> fac;
vector<int> invfac;

int C(int n,int k){
	ll r = 1LL*((1LL*fac[n]*invfac[k])%MOD)*invfac[n-k]%MOD;
	return r;
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,k;cin>>n>>k;	
	fac.resize(k+1);
	invfac.resize(k+1);
	fac[0]=1;
	for(int i=1;i<=k;i++) fac[i] = (1LL*fac[i-1]*i)%MOD;
	ll g = fac[k];
	ll r = 1;
	ll p = MOD-2;
	while(p){
		if(p&1) r = (r*g)%MOD;
		g = (g*g)%MOD;
		p>>=1;
	}
	invfac[k]=r;
	for(int i=k;i>=1;i--){
		invfac[i-1] = (1LL*invfac[i]*i)%MOD;
	}
	vector<int> arr(n-k+1);
	for(int i=0;i<n-k+1;i++){
		cin>>arr[i];
	}
	dsu d;
	d.init(n);
	vector<int> hasto(n,-1);
	for(int i=0;i<n-k;i++){
		if(arr[i]==arr[i+1]){
			d.join(i,i+k);
		}else if(arr[i]+1==arr[i+1]){
			hasto[i]=0;
			hasto[i+k]=1;
		}else{
			hasto[i]=1;
			hasto[i+k]=0;
		}
	}
	for(int i=0;i<n;i++)	{
		int a = d.query(i);
		if(hasto[i]!=-1) hasto[a]=hasto[i];
	}
	for(int i=0;i<n;i++)	{
		hasto[i] = hasto[d.query(i)];
	}
	map<int,int> stuff;
	int cnt = 0;
	int cnt2 = 0;
	for(int i=0;i<k;i++){
		if(hasto[i]==1) cnt++;
		if(hasto[i]==-1){
			cnt2++;
		}
	}
	int K = arr[0]-cnt;
	cout<<C(cnt2,K)<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 0 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 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 0 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 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 0 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 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 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 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 500 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 0 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 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 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 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 500 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 51 ms 12628 KB Output is correct
36 Correct 57 ms 12624 KB Output is correct
37 Correct 56 ms 12824 KB Output is correct
38 Correct 61 ms 12624 KB Output is correct
39 Correct 52 ms 12628 KB Output is correct
40 Correct 68 ms 12824 KB Output is correct
41 Correct 55 ms 12836 KB Output is correct
42 Correct 55 ms 13188 KB Output is correct
43 Correct 59 ms 13084 KB Output is correct
44 Correct 59 ms 25172 KB Output is correct
45 Correct 56 ms 25168 KB Output is correct
46 Correct 66 ms 25156 KB Output is correct
47 Correct 67 ms 18456 KB Output is correct
48 Correct 53 ms 12804 KB Output is correct
49 Correct 55 ms 12628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 0 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 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 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 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 500 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 51 ms 12628 KB Output is correct
36 Correct 57 ms 12624 KB Output is correct
37 Correct 56 ms 12824 KB Output is correct
38 Correct 61 ms 12624 KB Output is correct
39 Correct 52 ms 12628 KB Output is correct
40 Correct 68 ms 12824 KB Output is correct
41 Correct 55 ms 12836 KB Output is correct
42 Correct 55 ms 13188 KB Output is correct
43 Correct 59 ms 13084 KB Output is correct
44 Correct 59 ms 25172 KB Output is correct
45 Correct 56 ms 25168 KB Output is correct
46 Correct 66 ms 25156 KB Output is correct
47 Correct 67 ms 18456 KB Output is correct
48 Correct 53 ms 12804 KB Output is correct
49 Correct 55 ms 12628 KB Output is correct
50 Correct 66 ms 12068 KB Output is correct
51 Correct 68 ms 12116 KB Output is correct
52 Correct 65 ms 12196 KB Output is correct
53 Correct 77 ms 12112 KB Output is correct
54 Correct 66 ms 12068 KB Output is correct
55 Correct 70 ms 12056 KB Output is correct
56 Correct 63 ms 12116 KB Output is correct
57 Correct 62 ms 12116 KB Output is correct
58 Correct 70 ms 12112 KB Output is correct
59 Correct 66 ms 12052 KB Output is correct
60 Correct 63 ms 12068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 0 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 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 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 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 500 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 51 ms 12628 KB Output is correct
36 Correct 57 ms 12624 KB Output is correct
37 Correct 56 ms 12824 KB Output is correct
38 Correct 61 ms 12624 KB Output is correct
39 Correct 52 ms 12628 KB Output is correct
40 Correct 68 ms 12824 KB Output is correct
41 Correct 55 ms 12836 KB Output is correct
42 Correct 55 ms 13188 KB Output is correct
43 Correct 59 ms 13084 KB Output is correct
44 Correct 59 ms 25172 KB Output is correct
45 Correct 56 ms 25168 KB Output is correct
46 Correct 66 ms 25156 KB Output is correct
47 Correct 67 ms 18456 KB Output is correct
48 Correct 53 ms 12804 KB Output is correct
49 Correct 55 ms 12628 KB Output is correct
50 Correct 66 ms 12068 KB Output is correct
51 Correct 68 ms 12116 KB Output is correct
52 Correct 65 ms 12196 KB Output is correct
53 Correct 77 ms 12112 KB Output is correct
54 Correct 66 ms 12068 KB Output is correct
55 Correct 70 ms 12056 KB Output is correct
56 Correct 63 ms 12116 KB Output is correct
57 Correct 62 ms 12116 KB Output is correct
58 Correct 70 ms 12112 KB Output is correct
59 Correct 66 ms 12052 KB Output is correct
60 Correct 63 ms 12068 KB Output is correct
61 Correct 19 ms 15960 KB Output is correct
62 Correct 19 ms 15964 KB Output is correct
63 Correct 19 ms 15964 KB Output is correct
64 Correct 20 ms 15964 KB Output is correct
65 Correct 45 ms 14020 KB Output is correct
66 Correct 40 ms 14676 KB Output is correct
67 Correct 64 ms 13136 KB Output is correct
68 Correct 23 ms 15704 KB Output is correct
69 Correct 19 ms 15960 KB Output is correct
70 Correct 19 ms 15976 KB Output is correct
71 Correct 19 ms 15964 KB Output is correct