Submission #239550

# Submission time Handle Problem Language Result Execution time Memory
239550 2020-06-16T09:53:00 Z kshitij_sodani Ljetopica (COI19_ljetopica) C++17
100 / 100
105 ms 31872 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
llo n,k;
llo it[1001];
llo mod=1000000007;
llo pre[1001];
llo st=1;
llo dp[1001][1002][2];
llo co[1001][1002][2];
llo solve(llo cc[]){
	//1-less
	//0-same
	memset(dp,0,sizeof(dp));
	memset(co,0,sizeof(co));
	
	co[0][0][0]=1;
	dp[0][0][0]=1;
//	dp[0][0][1];
//	dp[0][1][0];
	//dp[0][1][1];
	for(llo i=1;i<n;i++){
		for(llo l=0;l<min(k+1,i+1);l++){
			if((it[i-1]+l)%2==0){
				if(cc[i]==0){
					for(llo j=l;j>=0 and j>=l-1;j--){
						co[i][l][1]+=co[i-1][j][1];
						co[i][l][1]%=mod;

						dp[i][l][1]+=dp[i-1][j][1]*2;
						dp[i][l][1]%=mod;

						co[i][l][0]+=co[i-1][j][0];
						co[i][l][0]%=mod;

						dp[i][l][0]+=dp[i-1][j][0]*2;
						dp[i][l][0]%=mod;
						
					}
				}
				else{	
					for(llo j=l;j>=0 and j>=l-1;j--){
						co[i][l][1]+=co[i-1][j][1]+co[i-1][j][0];
						dp[i][l][1]+=2*(dp[i-1][j][1]+dp[i-1][j][0]);
						dp[i][l][1]%=mod;
						co[i][l][1]%=mod;

					}
				}
			}
			else{
				if(cc[i]==0){
					for(llo j=l;j>=0 and j>=l-1;j--){
						co[i][l][1]+=co[i-1][j][1];
						dp[i][l][1]+=2*dp[i-1][j][1]+co[i-1][j][1];
						co[i][l][1]%=mod;
						dp[i][l][1]%=mod;
					}
				}
				else{
					for(llo j=l;j>=0 and j>=l-1;j--){
						co[i][l][1]+=co[i-1][j][1];
						dp[i][l][1]+=dp[i-1][j][1]*2+co[i-1][j][1];
						co[i][l][1]%=mod;
						dp[i][l][1]%=mod;

						co[i][l][0]+=co[i-1][j][0];
						dp[i][l][0]+=2*dp[i-1][j][0]+co[i-1][j][0];
						co[i][l][0]%=mod;
						dp[i][l][0]%=mod;
					}
				}
			}
		}
	}
	llo kk=0;
	kk+=dp[n-1][k][1];
/*	for(llo i=0;i<n;i++){
		for(llo j=0;j<k+1;j++){
			cout<<dp[i][j][0]<<",";
		}
		cout<<endl;
	}
	cout<<endl;
	for(llo i=0;i<n;i++){
		for(llo j=0;j<k+1;j++){
			cout<<dp[i][j][1]<<",";
		}
		cout<<endl;
	}*/
	if(st){
		kk+=dp[n-1][k][0];
	}
	return kk;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>k;
	pre[0]=1;
	for(llo i=1;i<n+1;i++){
		pre[i]=pre[i-1]*2;
		pre[i]%=mod;
	}
	llo aa[n];
	llo bb[n];
	string s;
	cin>>s;
	for(llo i=0;i<n-1;i++){
		if(s[i]=='L'){
			it[i]=0;
		}
		else{
			it[i]=1;
		}
	}
	cin>>s;
	for(llo i=0;i<n;i++){
		if(s[i]=='0'){
			aa[i]=0;
		}
		else{
			aa[i]=1;
		}
	}
	cin>>s;
	for(llo i=0;i<n;i++){
		if(s[i]=='0'){
			bb[i]=0;
		}
		else{
			bb[i]=1;
		}
	}
	llo ans=0;
/*
	for(llo i=n-1;i>=0;i--){
		if(aa[i]==1){
			for(llo j=i+1;j<n;j++){
				aa[j]=1;
			}
			aa[i]=0;
			break;
		}
	}*/
	ans+=solve(bb);
	st=0;
//	cout<<ans<<endl;
	ans-=solve(aa);
//	cout<<ans<<endl;

	for(llo i=0;i<n;i++){
		it[i]=1-it[i];
	}
	st=1;
	ans+=solve(bb);
//	cout<<ans<<endl;
	st=0;
	ans-=solve(aa);
//	cout<<ans<<endl;

	ans+=2*mod;
	ans%=mod;
	cout<<ans<<endl;





	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 32 ms 31744 KB Output is correct
2 Correct 37 ms 31744 KB Output is correct
3 Correct 32 ms 31744 KB Output is correct
4 Correct 33 ms 31744 KB Output is correct
5 Correct 32 ms 31744 KB Output is correct
6 Correct 32 ms 31744 KB Output is correct
7 Correct 38 ms 31744 KB Output is correct
8 Correct 32 ms 31744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 31744 KB Output is correct
2 Correct 31 ms 31744 KB Output is correct
3 Correct 37 ms 31872 KB Output is correct
4 Correct 32 ms 31744 KB Output is correct
5 Correct 33 ms 31744 KB Output is correct
6 Correct 32 ms 31744 KB Output is correct
7 Correct 32 ms 31744 KB Output is correct
8 Correct 31 ms 31744 KB Output is correct
9 Correct 34 ms 31864 KB Output is correct
10 Correct 32 ms 31744 KB Output is correct
11 Correct 31 ms 31744 KB Output is correct
12 Correct 35 ms 31744 KB Output is correct
13 Correct 34 ms 31744 KB Output is correct
14 Correct 35 ms 31744 KB Output is correct
15 Correct 34 ms 31744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 31864 KB Output is correct
2 Correct 74 ms 31744 KB Output is correct
3 Correct 79 ms 31744 KB Output is correct
4 Correct 105 ms 31864 KB Output is correct
5 Correct 72 ms 31744 KB Output is correct
6 Correct 97 ms 31744 KB Output is correct
7 Correct 59 ms 31744 KB Output is correct
8 Correct 79 ms 31744 KB Output is correct
9 Correct 38 ms 31864 KB Output is correct
10 Correct 78 ms 31744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 31744 KB Output is correct
2 Correct 37 ms 31744 KB Output is correct
3 Correct 32 ms 31744 KB Output is correct
4 Correct 33 ms 31744 KB Output is correct
5 Correct 32 ms 31744 KB Output is correct
6 Correct 32 ms 31744 KB Output is correct
7 Correct 38 ms 31744 KB Output is correct
8 Correct 32 ms 31744 KB Output is correct
9 Correct 32 ms 31744 KB Output is correct
10 Correct 31 ms 31744 KB Output is correct
11 Correct 37 ms 31872 KB Output is correct
12 Correct 32 ms 31744 KB Output is correct
13 Correct 33 ms 31744 KB Output is correct
14 Correct 32 ms 31744 KB Output is correct
15 Correct 32 ms 31744 KB Output is correct
16 Correct 31 ms 31744 KB Output is correct
17 Correct 34 ms 31864 KB Output is correct
18 Correct 32 ms 31744 KB Output is correct
19 Correct 31 ms 31744 KB Output is correct
20 Correct 35 ms 31744 KB Output is correct
21 Correct 34 ms 31744 KB Output is correct
22 Correct 35 ms 31744 KB Output is correct
23 Correct 34 ms 31744 KB Output is correct
24 Correct 87 ms 31864 KB Output is correct
25 Correct 74 ms 31744 KB Output is correct
26 Correct 79 ms 31744 KB Output is correct
27 Correct 105 ms 31864 KB Output is correct
28 Correct 72 ms 31744 KB Output is correct
29 Correct 97 ms 31744 KB Output is correct
30 Correct 59 ms 31744 KB Output is correct
31 Correct 79 ms 31744 KB Output is correct
32 Correct 38 ms 31864 KB Output is correct
33 Correct 78 ms 31744 KB Output is correct
34 Correct 90 ms 31744 KB Output is correct
35 Correct 60 ms 31736 KB Output is correct
36 Correct 74 ms 31872 KB Output is correct
37 Correct 90 ms 31744 KB Output is correct
38 Correct 47 ms 31744 KB Output is correct
39 Correct 93 ms 31744 KB Output is correct
40 Correct 43 ms 31744 KB Output is correct
41 Correct 80 ms 31744 KB Output is correct
42 Correct 94 ms 31864 KB Output is correct
43 Correct 94 ms 31744 KB Output is correct
44 Correct 86 ms 31744 KB Output is correct
45 Correct 58 ms 31744 KB Output is correct
46 Correct 83 ms 31744 KB Output is correct
47 Correct 91 ms 31864 KB Output is correct
48 Correct 71 ms 31744 KB Output is correct
49 Correct 39 ms 31744 KB Output is correct
50 Correct 101 ms 31744 KB Output is correct
51 Correct 69 ms 31744 KB Output is correct
52 Correct 73 ms 31824 KB Output is correct
53 Correct 104 ms 31744 KB Output is correct
54 Correct 65 ms 31744 KB Output is correct
55 Correct 96 ms 31744 KB Output is correct
56 Correct 95 ms 31744 KB Output is correct
57 Correct 48 ms 31744 KB Output is correct
58 Correct 92 ms 31744 KB Output is correct