# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
21285 | 2017-04-12T10:06:20 Z | suzy | 능력 (kriii4_S) | C++11 | 1533 ms | 392052 KB |
#include <stdio.h> #include <string.h> typedef long long lli; #define MOD 1000000007LL lli p[5001], q[5001], d[5001], fac[5001]; int n; lli r[5001][5001], rd[5001][5001]; lli pw(lli n, lli x) { if(x==0) return 1; if(x%2) return n*pw(n,x-1)%MOD; else { lli ret=pw(n,x/2); return ret*ret%MOD; } } int main() { memset(rd,-1,sizeof(rd)); fac[0]=1; for(lli i=1;i<=5000;i++) fac[i]=fac[i-1]*i%MOD; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lld %lld",&p[i],&d[i]); q[i]=(1000000000-p[i])*pw(1000000000,MOD-2)%MOD; p[i]=p[i]*pw(1000000000,MOD-2)%MOD; } for(int i=0;i<=5000;i++) { r[0][i]=1; } for(int j=1;j<=n;j++) { for(int i=1;i<=n;i++) r[i][j]=(r[i-1][j-1]*q[j]%MOD+r[i][j-1])%MOD; } for(int i=0;i<=n;i++) { rd[0][i]=1; } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { rd[i][j]=(r[i][n]-rd[i-1][j]*q[j]%MOD+MOD)%MOD; } } lli res=0; for(int i=1;i<=n;i++) { lli mult=p[i]*d[i]%MOD, add=0; for(int j=0;j<=n-1;j++) { lli ff=fac[j]*fac[n-j-1]%MOD; add+=ff*rd[j][i]%MOD; add%=MOD; } res+=add*mult%MOD; res%=MOD; } res*=pw(fac[n],MOD-2); res%=MOD; printf("%lld\n",res); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 392052 KB | Output is correct |
2 | Correct | 16 ms | 392052 KB | Output is correct |
3 | Correct | 6 ms | 392052 KB | Output is correct |
4 | Correct | 13 ms | 392052 KB | Output is correct |
5 | Correct | 6 ms | 392052 KB | Output is correct |
6 | Correct | 6 ms | 392052 KB | Output is correct |
7 | Correct | 9 ms | 392052 KB | Output is correct |
8 | Correct | 16 ms | 392052 KB | Output is correct |
9 | Correct | 16 ms | 392052 KB | Output is correct |
10 | Correct | 6 ms | 392052 KB | Output is correct |
11 | Correct | 16 ms | 392052 KB | Output is correct |
12 | Correct | 13 ms | 392052 KB | Output is correct |
13 | Correct | 16 ms | 392052 KB | Output is correct |
14 | Correct | 16 ms | 392052 KB | Output is correct |
15 | Correct | 13 ms | 392052 KB | Output is correct |
16 | Correct | 29 ms | 392052 KB | Output is correct |
17 | Correct | 19 ms | 392052 KB | Output is correct |
18 | Correct | 19 ms | 392052 KB | Output is correct |
19 | Correct | 6 ms | 392052 KB | Output is correct |
20 | Correct | 13 ms | 392052 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1493 ms | 392052 KB | Output is correct |
2 | Correct | 1503 ms | 392052 KB | Output is correct |
3 | Correct | 1479 ms | 392052 KB | Output is correct |
4 | Correct | 1489 ms | 392052 KB | Output is correct |
5 | Correct | 1533 ms | 392052 KB | Output is correct |
6 | Correct | 1533 ms | 392052 KB | Output is correct |
7 | Correct | 1463 ms | 392052 KB | Output is correct |
8 | Correct | 1509 ms | 392052 KB | Output is correct |
9 | Correct | 1453 ms | 392052 KB | Output is correct |
10 | Correct | 1506 ms | 392052 KB | Output is correct |
11 | Correct | 1506 ms | 392052 KB | Output is correct |
12 | Correct | 1463 ms | 392052 KB | Output is correct |
13 | Correct | 1446 ms | 392052 KB | Output is correct |
14 | Correct | 1466 ms | 392052 KB | Output is correct |
15 | Correct | 1429 ms | 392052 KB | Output is correct |
16 | Correct | 1473 ms | 392052 KB | Output is correct |
17 | Correct | 1383 ms | 392052 KB | Output is correct |
18 | Correct | 1459 ms | 392052 KB | Output is correct |
19 | Correct | 1393 ms | 392052 KB | Output is correct |
20 | Correct | 1416 ms | 392052 KB | Output is correct |