Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const int maxn = 100000 + 100;
- const int maxm = 1000 + 100;
- const LL MOD = 998244853;
- int n, m;
- LL a[maxn], p[maxn], dp[2][maxm];
- int main() {
- #ifdef ExRoc
- freopen("test.txt", "r", stdin);
- #endif // ExRoc
- ios::sync_with_stdio(false);
- cin >> n >> m;
- for (int i = 1; i <= n; ++i) {
- cin >> a[i];
- a[i] %= m;
- }
- for (int i = 1; i <= n; ++i) {
- cin >> p[i];
- p[i] %= MOD;
- }
- dp[0][0] = 1;
- for (int i = 1; i <= n; ++i) {
- int nowi = i % 2;
- int prei = nowi ^ 1;
- for (int j = 0; j < m; ++j) {
- dp[nowi][j] = (dp[prei][j] * ((((1 - p[i]) % MOD) + MOD) % MOD) % MOD + dp[prei][(j - a[i] + m) % m] * p[i] % MOD) % MOD;
- }
- }
- cout << dp[n & 1][0] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement