10626 | 2024-04-06 23:54:42 | 111 | Tömbök előállítása | cpp17 | Runtime error 52/100 | 527ms | 5532 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 19ms | 2808 KiB | ||||
2 | Accepted | 26ms | 3072 KiB | ||||
3 | Accepted | 59ms | 3348 KiB | ||||
subtask2 | 10/10 | ||||||
4 | Accepted | 25ms | 3560 KiB | ||||
5 | Accepted | 25ms | 3512 KiB | ||||
6 | Accepted | 26ms | 3632 KiB | ||||
subtask3 | 10/10 | ||||||
7 | Accepted | 64ms | 3848 KiB | ||||
8 | Accepted | 87ms | 4396 KiB | ||||
9 | Accepted | 82ms | 4180 KiB | ||||
10 | Accepted | 109ms | 4220 KiB | ||||
11 | Accepted | 104ms | 4184 KiB | ||||
12 | Accepted | 104ms | 4408 KiB | ||||
13 | Accepted | 109ms | 4616 KiB | ||||
subtask4 | 7/7 | ||||||
14 | Accepted | 109ms | 4828 KiB | ||||
15 | Accepted | 115ms | 5088 KiB | ||||
16 | Accepted | 98ms | 5180 KiB | ||||
17 | Accepted | 70ms | 5032 KiB | ||||
18 | Accepted | 75ms | 5204 KiB | ||||
19 | Accepted | 97ms | 5052 KiB | ||||
20 | Accepted | 109ms | 4984 KiB | ||||
subtask5 | 0/8 | ||||||
21 | Runtime error | 4ms | 4680 KiB | ||||
22 | Runtime error | 3ms | 4656 KiB | ||||
23 | Runtime error | 3ms | 4728 KiB | ||||
24 | Runtime error | 3ms | 4712 KiB | ||||
25 | Runtime error | 3ms | 4716 KiB | ||||
26 | Runtime error | 3ms | 4820 KiB | ||||
27 | Runtime error | 3ms | 4968 KiB | ||||
28 | Runtime error | 3ms | 4824 KiB | ||||
29 | Runtime error | 3ms | 4720 KiB | ||||
30 | Runtime error | 3ms | 4788 KiB | ||||
subtask6 | 25/25 | ||||||
31 | Accepted | 476ms | 5244 KiB | ||||
32 | Accepted | 476ms | 5248 KiB | ||||
33 | Accepted | 527ms | 5248 KiB | ||||
34 | Accepted | 509ms | 5532 KiB | ||||
35 | Accepted | 245ms | 5372 KiB | ||||
36 | Accepted | 256ms | 5252 KiB | ||||
37 | Accepted | 476ms | 5256 KiB | ||||
38 | Accepted | 279ms | 5272 KiB | ||||
39 | Accepted | 284ms | 5276 KiB | ||||
40 | Accepted | 504ms | 5384 KiB | ||||
subtask7 | 0/40 | ||||||
41 | Runtime error | 3ms | 4928 KiB | ||||
42 | Runtime error | 4ms | 5020 KiB | ||||
43 | Runtime error | 4ms | 4928 KiB | ||||
44 | Runtime error | 4ms | 4928 KiB | ||||
45 | Runtime error | 4ms | 4932 KiB | ||||
46 | Runtime error | 4ms | 5024 KiB | ||||
47 | Runtime error | 4ms | 4920 KiB | ||||
48 | Accepted | 307ms | 5380 KiB | ||||
49 | Runtime error | 4ms | 5080 KiB | ||||
50 | Runtime error | 4ms | 5032 KiB |