#include<bits/stdc++.h>
using namespace std;
long long mod=1e9+7;
long long n,c,a[100005],b[100005],q,dp[100005][35];
long long f(int x,int cal)
{
if(x>=n)
{
if(cal>=c)return 1;
else return 0;
}
if(dp[x][cal]!=-1)return dp[x][cal];
long long num=0;
num+=a[x]*f(x+1,min(c,(long long)cal+1));
num%=10007;
num+=b[x]*f(x+1,cal);
num%=10007;
return dp[x][cal]=num;
}
int main()
{
cin>>n>>c;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>b[i];
cin>>q;
for(int i=0;i<q;i++)
{
memset(dp,-1,sizeof dp);
long long x,y,z;
cin>>x>>y>>z;
a[x-1]=y;
b[x-1]=z;
cout<<f(0,0)<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3546 ms |
27768 KB |
Output is correct |
2 |
Execution timed out |
4033 ms |
27768 KB |
Time limit exceeded |
3 |
Correct |
3852 ms |
27840 KB |
Output is correct |
4 |
Execution timed out |
4027 ms |
33180 KB |
Time limit exceeded |
5 |
Execution timed out |
4022 ms |
36420 KB |
Time limit exceeded |
6 |
Execution timed out |
4038 ms |
36728 KB |
Time limit exceeded |
7 |
Execution timed out |
4027 ms |
34040 KB |
Time limit exceeded |
8 |
Execution timed out |
4024 ms |
36728 KB |
Time limit exceeded |
9 |
Execution timed out |
4025 ms |
35192 KB |
Time limit exceeded |
10 |
Execution timed out |
4014 ms |
34808 KB |
Time limit exceeded |