#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 10007;
const int LOG = 20;
const int maxn = 1e5 + 5;
ll dp[1005][21];
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, m; cin >> n >> m;
vector<int> A(n+1), B(n+1);
for(int i=1; i<=n; i++) cin >> A[i];
for(int i=1; i<=n; i++) cin >> B[i];
int q; cin >> q;
while(q--) {
int p, na, nb; cin >> p >> na >> nb;
A[p] = na; B[p] = nb;
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for(int i=1; i<=n; i++) {
for(int j=0; j<=m; j++) {
if(j) dp[i][j] = (dp[i][j] + dp[i-1][j-1] * A[i]) % mod;
dp[i][j] = (dp[i][j] + dp[i-1][j] * B[i]) % mod;
if(j == m) dp[i][j] = (dp[i][j] + dp[i-1][j] * A[i]) % mod;
}
}
cout << dp[n][m] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
604 KB |
Output is correct |
2 |
Correct |
51 ms |
604 KB |
Output is correct |
3 |
Correct |
55 ms |
604 KB |
Output is correct |
4 |
Runtime error |
8 ms |
2908 KB |
Execution killed with signal 11 |
5 |
Runtime error |
12 ms |
4188 KB |
Execution killed with signal 11 |
6 |
Runtime error |
16 ms |
4236 KB |
Execution killed with signal 11 |
7 |
Runtime error |
9 ms |
3160 KB |
Execution killed with signal 11 |
8 |
Runtime error |
13 ms |
4188 KB |
Execution killed with signal 11 |
9 |
Runtime error |
11 ms |
3668 KB |
Execution killed with signal 11 |
10 |
Runtime error |
10 ms |
3420 KB |
Execution killed with signal 11 |