10625 | 2024-04-06 23:46:17 | 111 | Tömbök előállítása | cpp17 | Runtime error 52/100 | 532ms | 5424 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 26ms | 2964 KiB | ||||
2 | Accepted | 30ms | 3252 KiB | ||||
3 | Accepted | 64ms | 3692 KiB | ||||
subtask2 | 10/10 | ||||||
4 | Accepted | 30ms | 3760 KiB | ||||
5 | Accepted | 30ms | 3988 KiB | ||||
6 | Accepted | 30ms | 4092 KiB | ||||
subtask3 | 10/10 | ||||||
7 | Accepted | 70ms | 4116 KiB | ||||
8 | Accepted | 93ms | 4496 KiB | ||||
9 | Accepted | 86ms | 4732 KiB | ||||
10 | Accepted | 115ms | 5036 KiB | ||||
11 | Accepted | 109ms | 4760 KiB | ||||
12 | Accepted | 109ms | 4712 KiB | ||||
13 | Accepted | 115ms | 4720 KiB | ||||
subtask4 | 7/7 | ||||||
14 | Accepted | 115ms | 4844 KiB | ||||
15 | Accepted | 120ms | 4860 KiB | ||||
16 | Accepted | 104ms | 5120 KiB | ||||
17 | Accepted | 75ms | 5068 KiB | ||||
18 | Accepted | 82ms | 5076 KiB | ||||
19 | Accepted | 104ms | 5080 KiB | ||||
20 | Accepted | 115ms | 5200 KiB | ||||
subtask5 | 0/8 | ||||||
21 | Runtime error | 4ms | 4616 KiB | ||||
22 | Runtime error | 4ms | 4812 KiB | ||||
23 | Runtime error | 4ms | 4636 KiB | ||||
24 | Runtime error | 4ms | 4720 KiB | ||||
25 | Wrong answer | 76ms | 5236 KiB | ||||
26 | Wrong answer | 64ms | 5236 KiB | ||||
27 | Runtime error | 4ms | 4656 KiB | ||||
28 | Wrong answer | 93ms | 5252 KiB | ||||
29 | Runtime error | 4ms | 4812 KiB | ||||
30 | Runtime error | 4ms | 4780 KiB | ||||
subtask6 | 25/25 | ||||||
31 | Accepted | 481ms | 5372 KiB | ||||
32 | Accepted | 481ms | 5268 KiB | ||||
33 | Accepted | 532ms | 5280 KiB | ||||
34 | Accepted | 515ms | 5284 KiB | ||||
35 | Accepted | 250ms | 5292 KiB | ||||
36 | Accepted | 261ms | 5292 KiB | ||||
37 | Accepted | 481ms | 5296 KiB | ||||
38 | Accepted | 284ms | 5300 KiB | ||||
39 | Accepted | 289ms | 5308 KiB | ||||
40 | Accepted | 509ms | 5424 KiB | ||||
subtask7 | 0/40 | ||||||
41 | Runtime error | 4ms | 4720 KiB | ||||
42 | Runtime error | 7ms | 4880 KiB | ||||
43 | Runtime error | 7ms | 4844 KiB | ||||
44 | Runtime error | 7ms | 4740 KiB | ||||
45 | Runtime error | 7ms | 4744 KiB | ||||
46 | Runtime error | 6ms | 4960 KiB | ||||
47 | Runtime error | 6ms | 4888 KiB | ||||
48 | Accepted | 312ms | 5412 KiB | ||||
49 | Runtime error | 6ms | 4984 KiB | ||||
50 | Runtime error | 4ms | 4952 KiB |