Submission #251657

#TimeUsernameProblemLanguageResultExecution timeMemory
251657VEGAnnRelativnost (COCI15_relativnost)C++14
42 / 140
4091 ms10872 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100100; const int C = 22; const int md = 10007; int n, c, a[N], b[N], f[N][C]; int mult(int x, int y) { return (x * y) % md; } void SUM(int &x, int y){ x += y; if (x >= md) x -= md; } int main() { #ifdef _LOCAL freopen("in.txt","r",stdin); // freopen("output.txt","w",stdout); #else // freopen("mining.in","r",stdin); freopen("mining.out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); #endif cin >> n >> c; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; int qq; cin >> qq; for (; qq; qq--){ int ps, an, bn; cin >> ps >> an >> bn; a[ps] = an; b[ps] = bn; for (int i = 0; i <= n; i++) for (int j = 0; j <= c; j++) f[i][j] = 0; f[0][0] = 1; for (int i = 0; i < n; i++) for (int j = 0; j <= c; j++){ if (f[i][j] == 0) continue; SUM(f[i + 1][min(j + 1, c)], mult(f[i][j], a[i + 1])); SUM(f[i + 1][j], mult(f[i][j], b[i + 1])); } cout << f[n][c] << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...