106252024-04-06 23:46:17111Tömbök előállításacpp17Runtime error 52/100532ms5424 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long

#define MOD 1000000007

using vec=array<int,100>;
using mat=array<array<int,100>,100>;

mat operator*(mat a,mat b){
	mat r{};
	for(int i=0;i<100;i++){
		for(int j=0;j<100;j++){
			for(int k=0;k<100;k++){
				r[i][j]+=a[i][k]*b[k][j];
				r[i][j]%=MOD;
			}
		}
	}
	return r;
}

vec operator*(vec a,mat b){
	vec r{};
	for(int i=0;i<100;i++){
		for(int j=0;j<100;j++){
			r[i]+=r[j]*b[i][j];
			r[i]%=MOD;
		}
	}
	return r;
}

mat mat_pow(mat x,int p){
	mat r{};
	for(int i=0;i<100;i++){
		r[i][i]=1;
	}
	while(p){
		if(p&1){
			r=r*x;
		}
		x=x*x;
		p>>=1;
	}
	return r;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N,M,L,R,K;
	cin>>N>>M>>L>>R>>K;
	vector<int>v(M);
	for(int i=0;i<M;i++){
		int s=L%M>i?L/M:L/M-1;
		int e=R%M<i?R/M-1:R/M;
		v[i]=e-s;
	}
	mat x{};
	for(int i=0;i<M;i++){
		for(int j=0;j<M;j++){
			x[i][j]=v[(j-i+M)%M];
		}
	}
	mat ans{};
	ans[0][0]=1;
	ans=ans*mat_pow(x,N);
	cout<<ans[0][K]<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted26ms2964 KiB
2Accepted30ms3252 KiB
3Accepted64ms3692 KiB
subtask210/10
4Accepted30ms3760 KiB
5Accepted30ms3988 KiB
6Accepted30ms4092 KiB
subtask310/10
7Accepted70ms4116 KiB
8Accepted93ms4496 KiB
9Accepted86ms4732 KiB
10Accepted115ms5036 KiB
11Accepted109ms4760 KiB
12Accepted109ms4712 KiB
13Accepted115ms4720 KiB
subtask47/7
14Accepted115ms4844 KiB
15Accepted120ms4860 KiB
16Accepted104ms5120 KiB
17Accepted75ms5068 KiB
18Accepted82ms5076 KiB
19Accepted104ms5080 KiB
20Accepted115ms5200 KiB
subtask50/8
21Runtime error4ms4616 KiB
22Runtime error4ms4812 KiB
23Runtime error4ms4636 KiB
24Runtime error4ms4720 KiB
25Wrong answer76ms5236 KiB
26Wrong answer64ms5236 KiB
27Runtime error4ms4656 KiB
28Wrong answer93ms5252 KiB
29Runtime error4ms4812 KiB
30Runtime error4ms4780 KiB
subtask625/25
31Accepted481ms5372 KiB
32Accepted481ms5268 KiB
33Accepted532ms5280 KiB
34Accepted515ms5284 KiB
35Accepted250ms5292 KiB
36Accepted261ms5292 KiB
37Accepted481ms5296 KiB
38Accepted284ms5300 KiB
39Accepted289ms5308 KiB
40Accepted509ms5424 KiB
subtask70/40
41Runtime error4ms4720 KiB
42Runtime error7ms4880 KiB
43Runtime error7ms4844 KiB
44Runtime error7ms4740 KiB
45Runtime error7ms4744 KiB
46Runtime error6ms4960 KiB
47Runtime error6ms4888 KiB
48Accepted312ms5412 KiB
49Runtime error6ms4984 KiB
50Runtime error4ms4952 KiB