106262024-04-06 23:54:42111Tömbök előállításacpp17Runtime error 52/100527ms5532 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;
}

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];
		}
	}
	x=mat_pow(x,N);
	cout<<x[0][K]<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted19ms2808 KiB
2Accepted26ms3072 KiB
3Accepted59ms3348 KiB
subtask210/10
4Accepted25ms3560 KiB
5Accepted25ms3512 KiB
6Accepted26ms3632 KiB
subtask310/10
7Accepted64ms3848 KiB
8Accepted87ms4396 KiB
9Accepted82ms4180 KiB
10Accepted109ms4220 KiB
11Accepted104ms4184 KiB
12Accepted104ms4408 KiB
13Accepted109ms4616 KiB
subtask47/7
14Accepted109ms4828 KiB
15Accepted115ms5088 KiB
16Accepted98ms5180 KiB
17Accepted70ms5032 KiB
18Accepted75ms5204 KiB
19Accepted97ms5052 KiB
20Accepted109ms4984 KiB
subtask50/8
21Runtime error4ms4680 KiB
22Runtime error3ms4656 KiB
23Runtime error3ms4728 KiB
24Runtime error3ms4712 KiB
25Runtime error3ms4716 KiB
26Runtime error3ms4820 KiB
27Runtime error3ms4968 KiB
28Runtime error3ms4824 KiB
29Runtime error3ms4720 KiB
30Runtime error3ms4788 KiB
subtask625/25
31Accepted476ms5244 KiB
32Accepted476ms5248 KiB
33Accepted527ms5248 KiB
34Accepted509ms5532 KiB
35Accepted245ms5372 KiB
36Accepted256ms5252 KiB
37Accepted476ms5256 KiB
38Accepted279ms5272 KiB
39Accepted284ms5276 KiB
40Accepted504ms5384 KiB
subtask70/40
41Runtime error3ms4928 KiB
42Runtime error4ms5020 KiB
43Runtime error4ms4928 KiB
44Runtime error4ms4928 KiB
45Runtime error4ms4932 KiB
46Runtime error4ms5024 KiB
47Runtime error4ms4920 KiB
48Accepted307ms5380 KiB
49Runtime error4ms5080 KiB
50Runtime error4ms5032 KiB