# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
21288 |
2017-04-12T12:40:55 Z |
gs14004 |
능력 (kriii4_S) |
C++11 |
|
2000 ms |
393544 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
lint ipow(lint x, lint p){
lint ret = 1, piv = x % mod;
while(p){
if(p&1) ret *= piv;
piv *= piv;
ret %= mod;
piv %= mod;
p >>= 1;
}
return ret % mod;
}
int n;
lint p[5005], d[5005], fact[5005];
lint d1[5005][5005], d2[5005][5005];
int main(){
cin >> n;
lint ans = 0;
fact[0] = 1;
for(int i=1; i<=n; i++){
fact[i] = fact[i-1] * i % mod;
cin >> p[i] >> d[i];
p[i] *= ipow(1000000000, mod - 2);
p[i] %= mod;
}
d1[0][0] = 1;
for(int i=1; i<=n; i++){
for(int j=0; j<=n; j++){
d1[i][j] = d1[i-1][j];
if(j > 0) d1[i][j] += d1[i-1][j-1] * (mod + 1 - p[i]);
d1[i][j] %= mod;
}
}
d2[n+1][0] = 1;
for(int i=n; i>=1; i--){
for(int j=0; j<=n; j++){
d2[i][j] = d2[i+1][j];
if(j > 0) d2[i][j] += d2[i+1][j-1] * (mod + 1 - p[i]);
d2[i][j] %= mod;
}
}
lint ret = 0;
for(int i=1; i<=n; i++){
lint cur = 0;
for(int j=0; j<n; j++){
for(int k=0; k<n; k++){
lint cp = d1[i-1][j] * d2[i+1][k] % mod;
cp *= fact[j + k];
cp %= mod;
cp *= fact[n - 1 - j - k];
cp %= mod;
cur += cp;
cur %= mod;
}
}
ret += cur * (p[i] * d[i] % mod) % mod;
ret %= mod;
}
ret *= ipow(fact[n], mod - 2);
ret %= mod;
cout << ret;
}
Compilation message
S.cpp: In function 'int main()':
S.cpp:26:7: warning: unused variable 'ans' [-Wunused-variable]
lint ans = 0;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
393544 KB |
Output is correct |
2 |
Correct |
83 ms |
393544 KB |
Output is correct |
3 |
Correct |
86 ms |
393544 KB |
Output is correct |
4 |
Correct |
86 ms |
393544 KB |
Output is correct |
5 |
Correct |
86 ms |
393544 KB |
Output is correct |
6 |
Correct |
86 ms |
393544 KB |
Output is correct |
7 |
Correct |
79 ms |
393544 KB |
Output is correct |
8 |
Correct |
89 ms |
393544 KB |
Output is correct |
9 |
Correct |
79 ms |
393544 KB |
Output is correct |
10 |
Correct |
83 ms |
393544 KB |
Output is correct |
11 |
Correct |
83 ms |
393544 KB |
Output is correct |
12 |
Correct |
79 ms |
393544 KB |
Output is correct |
13 |
Correct |
76 ms |
393544 KB |
Output is correct |
14 |
Correct |
99 ms |
393544 KB |
Output is correct |
15 |
Correct |
89 ms |
393544 KB |
Output is correct |
16 |
Correct |
56 ms |
393544 KB |
Output is correct |
17 |
Correct |
63 ms |
393544 KB |
Output is correct |
18 |
Correct |
63 ms |
393544 KB |
Output is correct |
19 |
Correct |
86 ms |
393544 KB |
Output is correct |
20 |
Correct |
56 ms |
393544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2000 ms |
393544 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |