답안 #374126

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
374126 2021-03-06T17:47:09 Z Nimbostratus Relativnost (COCI15_relativnost) C++17
42 / 140
4000 ms 20324 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define clean(a,s) memset((a),0,sizeof((a)[0])*(s))
#define all(x) (x).begin() , (x).end()
#define fi first
#define se second
#define int long long
using pii = pair<int,int>;
using ll = long long;
const int maxn = 1e5+5;
const int maxc = 25;
const int inf = 2e9;
const int mod = 10007;
 
int n,c,q,a[maxn],b[maxn],dp[maxn][maxc];
 
int32_t main () {
	//freopen("in","r",stdin); freopen("out","w",stdout);
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	cin >> n >> c;
	for(int i=1;i<=n;i++) cin >> a[i] , a[i] %= mod;
	for(int i=1;i<=n;i++) cin >> b[i] , b[i] %= mod;
	dp[0][0] = 1;
	for(int i=1;i<=n;i++) {
		dp[i][0] = dp[i-1][0]*b[i]%mod;
		for(int j=1;j<=min(i,c-1);j++)
			dp[i][j] = (a[i]*dp[i-1][j-1]%mod + b[i]*dp[i-1][j]%mod)%mod;
	}
	cin >> q;
	while(q--) {
		int idx,aa,bb;
		cin >> idx >> aa >> bb;
		a[idx] = aa%mod;
		b[idx] = bb%mod;
		for(int i=idx;i<=n;i++) {
			dp[i][0] = (dp[i-1][0]*b[i])%mod;
			for(int j=1;j<=min(i,c-1);j++)
				dp[i][j] = (a[i]*dp[i-1][j-1]%mod + b[i]*dp[i-1][j]%mod)%mod;
		}
		int mul = 1 , ans = 0;
		for(int i=1;i<=n;i++) mul = mul*(a[i]+b[i])%mod;
		for(int i=0;i<c;i++) ans = (ans + dp[n][i])%mod;
		ans = (mul - ans + 2*mod) % mod;
		cout << ans << endl;	
	}
}	
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 620 KB Output is correct
2 Correct 47 ms 492 KB Output is correct
3 Correct 49 ms 492 KB Output is correct
4 Execution timed out 4057 ms 12356 KB Time limit exceeded
5 Execution timed out 4042 ms 19164 KB Time limit exceeded
6 Execution timed out 4050 ms 20324 KB Time limit exceeded
7 Execution timed out 4048 ms 14316 KB Time limit exceeded
8 Execution timed out 4054 ms 20204 KB Time limit exceeded
9 Execution timed out 4067 ms 16668 KB Time limit exceeded
10 Execution timed out 4070 ms 15852 KB Time limit exceeded