# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
113387 | 2019-05-25T09:22:01 Z | 임유진(#2858) | Boat (APIO16_boat) | C++14 | 1379 ms | 14308 KB |
#include<stdio.h> #include<algorithm> using namespace std; #define MAXN 500 #define MOD 1000000007 long long inv[MAXN+1]; long long iCj[MAXN][MAXN], diCj[2*MAXN][MAXN+1]; long long g[MAXN][2*MAXN]; long long dp[MAXN+1][2*MAXN]; int main(){ int N; int a[MAXN+1], b[MAXN+1]; int c[2*MAXN], cn=1; int d[2*MAXN]; scanf("%d", &N); for(int i=1; i<=N; i++) scanf("%d%d", a+i, b+i); for(int i=1; i<=N; i++){ c[i*2-2]=a[i]-1; c[i*2-1]=b[i]; } sort(c, c+2*N); for(int i=1; i<2*N; i++) if(c[i]!=c[i-1]) c[cn++]=c[i]; for(int i=1; i<cn; i++) d[i]=c[i]-c[i-1]; for(int i=1; i<=N; i++){ inv[i]=1; long long p=i; for(int j=0; (1<<j)<=MOD-2; j++){ if(((MOD-2)&(1<<j))!=0) inv[i]=inv[i]*p%MOD; p=p*p%MOD; } } for(int i=0; i<N; i++) iCj[i][0]=1; for(int i=1; i<N; i++) for(int j=1; j<=i; j++) iCj[i][j]=(iCj[i-1][j-1]+iCj[i-1][j])%MOD; for(int i=1; i<cn; i++){ diCj[i][0]=1; for(int j=1; j<=d[i]&&j<=N; j++){ diCj[i][j]=diCj[i][j-1]*(d[i]-j+1)%MOD*inv[j]%MOD; //printf("%lld ", diCj[i][j]); } //printf("\n"); } for(int i=0; i<N; i++) for(int j=1; j<cn; j++){ g[i][j]=0; for(int k=0; k<=i; k++) g[i][j]=(g[i][j]+iCj[i][k]*diCj[j][k+1]%MOD)%MOD; } /* for(int i=0; i<N; i++){ for(int j=1; j<cn; j++) printf("%lld ", g[i][j]); printf("\n"); } */ for(int i=0; i<cn; i++) dp[0][i]=1; for(int i=1; i<=N; i++) dp[i][0]=1; for(int i=1; i<=N; i++) for(int j=1; j<cn; j++){ dp[i][j]=dp[i][j-1]; int f=0; for(int k=i; k>0; k--) if(a[k]<=c[j-1]+1&&c[j]<=b[k]){ //printf("%lld{%d} ", dp[i][j], f); dp[i][j]=(dp[i][j]+g[f++][j]*dp[k-1][j-1]%MOD)%MOD; } //printf("(%d %d %lld)\n", i, j, dp[i][j]); } printf("%lld", (dp[N][cn-1]-1+MOD)%MOD); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 804 ms | 14200 KB | Output is correct |
2 | Correct | 819 ms | 14072 KB | Output is correct |
3 | Correct | 826 ms | 14048 KB | Output is correct |
4 | Correct | 834 ms | 14104 KB | Output is correct |
5 | Correct | 855 ms | 14200 KB | Output is correct |
6 | Correct | 746 ms | 14200 KB | Output is correct |
7 | Correct | 747 ms | 14124 KB | Output is correct |
8 | Correct | 765 ms | 14216 KB | Output is correct |
9 | Correct | 749 ms | 14024 KB | Output is correct |
10 | Correct | 752 ms | 14276 KB | Output is correct |
11 | Correct | 773 ms | 14076 KB | Output is correct |
12 | Correct | 758 ms | 14112 KB | Output is correct |
13 | Correct | 844 ms | 14072 KB | Output is correct |
14 | Correct | 749 ms | 14200 KB | Output is correct |
15 | Correct | 760 ms | 14288 KB | Output is correct |
16 | Correct | 166 ms | 8228 KB | Output is correct |
17 | Correct | 175 ms | 8568 KB | Output is correct |
18 | Correct | 192 ms | 8336 KB | Output is correct |
19 | Correct | 180 ms | 8448 KB | Output is correct |
20 | Correct | 171 ms | 8524 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 804 ms | 14200 KB | Output is correct |
2 | Correct | 819 ms | 14072 KB | Output is correct |
3 | Correct | 826 ms | 14048 KB | Output is correct |
4 | Correct | 834 ms | 14104 KB | Output is correct |
5 | Correct | 855 ms | 14200 KB | Output is correct |
6 | Correct | 746 ms | 14200 KB | Output is correct |
7 | Correct | 747 ms | 14124 KB | Output is correct |
8 | Correct | 765 ms | 14216 KB | Output is correct |
9 | Correct | 749 ms | 14024 KB | Output is correct |
10 | Correct | 752 ms | 14276 KB | Output is correct |
11 | Correct | 773 ms | 14076 KB | Output is correct |
12 | Correct | 758 ms | 14112 KB | Output is correct |
13 | Correct | 844 ms | 14072 KB | Output is correct |
14 | Correct | 749 ms | 14200 KB | Output is correct |
15 | Correct | 760 ms | 14288 KB | Output is correct |
16 | Correct | 166 ms | 8228 KB | Output is correct |
17 | Correct | 175 ms | 8568 KB | Output is correct |
18 | Correct | 192 ms | 8336 KB | Output is correct |
19 | Correct | 180 ms | 8448 KB | Output is correct |
20 | Correct | 171 ms | 8524 KB | Output is correct |
21 | Correct | 911 ms | 13736 KB | Output is correct |
22 | Correct | 932 ms | 13816 KB | Output is correct |
23 | Correct | 910 ms | 13660 KB | Output is correct |
24 | Correct | 982 ms | 13700 KB | Output is correct |
25 | Correct | 965 ms | 13824 KB | Output is correct |
26 | Correct | 1163 ms | 13768 KB | Output is correct |
27 | Correct | 1198 ms | 13688 KB | Output is correct |
28 | Correct | 1120 ms | 13804 KB | Output is correct |
29 | Correct | 1145 ms | 13708 KB | Output is correct |
30 | Correct | 790 ms | 14168 KB | Output is correct |
31 | Correct | 747 ms | 14084 KB | Output is correct |
32 | Correct | 767 ms | 14148 KB | Output is correct |
33 | Correct | 751 ms | 14096 KB | Output is correct |
34 | Correct | 776 ms | 14036 KB | Output is correct |
35 | Correct | 842 ms | 14304 KB | Output is correct |
36 | Correct | 831 ms | 13944 KB | Output is correct |
37 | Correct | 836 ms | 14104 KB | Output is correct |
38 | Correct | 821 ms | 14176 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 2560 KB | Output is correct |
2 | Correct | 11 ms | 2560 KB | Output is correct |
3 | Correct | 11 ms | 2560 KB | Output is correct |
4 | Correct | 11 ms | 2660 KB | Output is correct |
5 | Correct | 11 ms | 2560 KB | Output is correct |
6 | Correct | 12 ms | 2560 KB | Output is correct |
7 | Correct | 12 ms | 2560 KB | Output is correct |
8 | Correct | 12 ms | 2688 KB | Output is correct |
9 | Correct | 12 ms | 2560 KB | Output is correct |
10 | Correct | 12 ms | 2560 KB | Output is correct |
11 | Correct | 11 ms | 2560 KB | Output is correct |
12 | Correct | 12 ms | 2688 KB | Output is correct |
13 | Correct | 12 ms | 2656 KB | Output is correct |
14 | Correct | 12 ms | 2560 KB | Output is correct |
15 | Correct | 13 ms | 2688 KB | Output is correct |
16 | Correct | 8 ms | 2176 KB | Output is correct |
17 | Correct | 8 ms | 2176 KB | Output is correct |
18 | Correct | 8 ms | 2176 KB | Output is correct |
19 | Correct | 8 ms | 2176 KB | Output is correct |
20 | Correct | 8 ms | 2048 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 804 ms | 14200 KB | Output is correct |
2 | Correct | 819 ms | 14072 KB | Output is correct |
3 | Correct | 826 ms | 14048 KB | Output is correct |
4 | Correct | 834 ms | 14104 KB | Output is correct |
5 | Correct | 855 ms | 14200 KB | Output is correct |
6 | Correct | 746 ms | 14200 KB | Output is correct |
7 | Correct | 747 ms | 14124 KB | Output is correct |
8 | Correct | 765 ms | 14216 KB | Output is correct |
9 | Correct | 749 ms | 14024 KB | Output is correct |
10 | Correct | 752 ms | 14276 KB | Output is correct |
11 | Correct | 773 ms | 14076 KB | Output is correct |
12 | Correct | 758 ms | 14112 KB | Output is correct |
13 | Correct | 844 ms | 14072 KB | Output is correct |
14 | Correct | 749 ms | 14200 KB | Output is correct |
15 | Correct | 760 ms | 14288 KB | Output is correct |
16 | Correct | 166 ms | 8228 KB | Output is correct |
17 | Correct | 175 ms | 8568 KB | Output is correct |
18 | Correct | 192 ms | 8336 KB | Output is correct |
19 | Correct | 180 ms | 8448 KB | Output is correct |
20 | Correct | 171 ms | 8524 KB | Output is correct |
21 | Correct | 911 ms | 13736 KB | Output is correct |
22 | Correct | 932 ms | 13816 KB | Output is correct |
23 | Correct | 910 ms | 13660 KB | Output is correct |
24 | Correct | 982 ms | 13700 KB | Output is correct |
25 | Correct | 965 ms | 13824 KB | Output is correct |
26 | Correct | 1163 ms | 13768 KB | Output is correct |
27 | Correct | 1198 ms | 13688 KB | Output is correct |
28 | Correct | 1120 ms | 13804 KB | Output is correct |
29 | Correct | 1145 ms | 13708 KB | Output is correct |
30 | Correct | 790 ms | 14168 KB | Output is correct |
31 | Correct | 747 ms | 14084 KB | Output is correct |
32 | Correct | 767 ms | 14148 KB | Output is correct |
33 | Correct | 751 ms | 14096 KB | Output is correct |
34 | Correct | 776 ms | 14036 KB | Output is correct |
35 | Correct | 842 ms | 14304 KB | Output is correct |
36 | Correct | 831 ms | 13944 KB | Output is correct |
37 | Correct | 836 ms | 14104 KB | Output is correct |
38 | Correct | 821 ms | 14176 KB | Output is correct |
39 | Correct | 12 ms | 2560 KB | Output is correct |
40 | Correct | 11 ms | 2560 KB | Output is correct |
41 | Correct | 11 ms | 2560 KB | Output is correct |
42 | Correct | 11 ms | 2660 KB | Output is correct |
43 | Correct | 11 ms | 2560 KB | Output is correct |
44 | Correct | 12 ms | 2560 KB | Output is correct |
45 | Correct | 12 ms | 2560 KB | Output is correct |
46 | Correct | 12 ms | 2688 KB | Output is correct |
47 | Correct | 12 ms | 2560 KB | Output is correct |
48 | Correct | 12 ms | 2560 KB | Output is correct |
49 | Correct | 11 ms | 2560 KB | Output is correct |
50 | Correct | 12 ms | 2688 KB | Output is correct |
51 | Correct | 12 ms | 2656 KB | Output is correct |
52 | Correct | 12 ms | 2560 KB | Output is correct |
53 | Correct | 13 ms | 2688 KB | Output is correct |
54 | Correct | 8 ms | 2176 KB | Output is correct |
55 | Correct | 8 ms | 2176 KB | Output is correct |
56 | Correct | 8 ms | 2176 KB | Output is correct |
57 | Correct | 8 ms | 2176 KB | Output is correct |
58 | Correct | 8 ms | 2048 KB | Output is correct |
59 | Correct | 1121 ms | 14268 KB | Output is correct |
60 | Correct | 1024 ms | 14064 KB | Output is correct |
61 | Correct | 1082 ms | 14088 KB | Output is correct |
62 | Correct | 1038 ms | 14296 KB | Output is correct |
63 | Correct | 1060 ms | 14164 KB | Output is correct |
64 | Correct | 1379 ms | 14124 KB | Output is correct |
65 | Correct | 1348 ms | 14296 KB | Output is correct |
66 | Correct | 1366 ms | 14044 KB | Output is correct |
67 | Correct | 1242 ms | 14016 KB | Output is correct |
68 | Correct | 1233 ms | 14180 KB | Output is correct |
69 | Correct | 1135 ms | 14120 KB | Output is correct |
70 | Correct | 1135 ms | 14308 KB | Output is correct |
71 | Correct | 1072 ms | 14100 KB | Output is correct |
72 | Correct | 1048 ms | 14108 KB | Output is correct |
73 | Correct | 1046 ms | 14200 KB | Output is correct |
74 | Correct | 199 ms | 8440 KB | Output is correct |
75 | Correct | 209 ms | 8488 KB | Output is correct |
76 | Correct | 213 ms | 8440 KB | Output is correct |
77 | Correct | 209 ms | 8496 KB | Output is correct |
78 | Correct | 207 ms | 8380 KB | Output is correct |