# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
118609 | 2019-06-19T09:45:22 Z | pzdba | Boat (APIO16_boat) | C++14 | 576 ms | 4512 KB |
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int mod = 1e9+7; vector<int> h; int a[505], b[505], l[1005]; LL dp[505][1005]; LL inv[505]; LL go(LL a, LL b){ LL ans=1; while(b){ if(b%2) ans=ans*a%mod; a=a*a%mod; b/=2; } return ans; } int main(){ int n; scanf("%d", &n); for(int i=0;i<=n;i++) inv[i] = go(i, mod-2); for(int i=1;i<=n;i++){ scanf("%d%d", &a[i], &b[i]); h.push_back(a[i]-1); h.push_back(b[i]); } sort(h.begin(), h.end()); h.erase(unique(h.begin(), h.end()), h.end()); for(int i=1;i<=n;i++){ a[i] = lower_bound(h.begin(), h.end(), a[i]-1) - h.begin() + 1; b[i] = lower_bound(h.begin(), h.end(), b[i]) - h.begin() + 1; } l[1] = h[0]; for(int i=2;i<=h.size();i++) l[i] = h[i-1] - h[i-2]; for(int i=1;i<=n;i++){ for(int j=1;j<=h.size();j++){ if(i == 1){ if(a[i] < j && j <= b[i]) dp[i][j] = (dp[i][j] + l[j])%mod; } else{ if(a[i] < j && j <= b[i]){ dp[i][j] = (dp[i][j] + l[j] + l[j]*dp[i-1][j-1])%mod; int cnt = 1; LL sum = l[j]-1; for(int k=i-1;k>=1;k--){ if(a[k] < j && j <= b[k]){ cnt++; sum = sum*(l[j]+cnt-2)%mod*inv[cnt]%mod; dp[i][j] = (dp[i][j] + sum + sum*dp[k-1][j-1])%mod; } } } } dp[i][j] = (dp[i][j] + dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1] + mod)%mod; } } printf("%lld\n", dp[n][h.size()]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 4224 KB | Output is correct |
2 | Correct | 10 ms | 4224 KB | Output is correct |
3 | Correct | 10 ms | 4224 KB | Output is correct |
4 | Correct | 10 ms | 4224 KB | Output is correct |
5 | Correct | 10 ms | 4352 KB | Output is correct |
6 | Correct | 10 ms | 4352 KB | Output is correct |
7 | Correct | 11 ms | 4396 KB | Output is correct |
8 | Correct | 10 ms | 4352 KB | Output is correct |
9 | Correct | 10 ms | 4352 KB | Output is correct |
10 | Correct | 10 ms | 4224 KB | Output is correct |
11 | Correct | 10 ms | 4224 KB | Output is correct |
12 | Correct | 10 ms | 4224 KB | Output is correct |
13 | Correct | 10 ms | 4352 KB | Output is correct |
14 | Correct | 10 ms | 4352 KB | Output is correct |
15 | Correct | 10 ms | 4352 KB | Output is correct |
16 | Correct | 6 ms | 3072 KB | Output is correct |
17 | Correct | 6 ms | 3072 KB | Output is correct |
18 | Correct | 6 ms | 3072 KB | Output is correct |
19 | Correct | 6 ms | 3072 KB | Output is correct |
20 | Correct | 6 ms | 3072 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 4224 KB | Output is correct |
2 | Correct | 10 ms | 4224 KB | Output is correct |
3 | Correct | 10 ms | 4224 KB | Output is correct |
4 | Correct | 10 ms | 4224 KB | Output is correct |
5 | Correct | 10 ms | 4352 KB | Output is correct |
6 | Correct | 10 ms | 4352 KB | Output is correct |
7 | Correct | 11 ms | 4396 KB | Output is correct |
8 | Correct | 10 ms | 4352 KB | Output is correct |
9 | Correct | 10 ms | 4352 KB | Output is correct |
10 | Correct | 10 ms | 4224 KB | Output is correct |
11 | Correct | 10 ms | 4224 KB | Output is correct |
12 | Correct | 10 ms | 4224 KB | Output is correct |
13 | Correct | 10 ms | 4352 KB | Output is correct |
14 | Correct | 10 ms | 4352 KB | Output is correct |
15 | Correct | 10 ms | 4352 KB | Output is correct |
16 | Correct | 6 ms | 3072 KB | Output is correct |
17 | Correct | 6 ms | 3072 KB | Output is correct |
18 | Correct | 6 ms | 3072 KB | Output is correct |
19 | Correct | 6 ms | 3072 KB | Output is correct |
20 | Correct | 6 ms | 3072 KB | Output is correct |
21 | Correct | 207 ms | 4324 KB | Output is correct |
22 | Correct | 207 ms | 4272 KB | Output is correct |
23 | Correct | 182 ms | 4292 KB | Output is correct |
24 | Correct | 208 ms | 4444 KB | Output is correct |
25 | Correct | 216 ms | 4216 KB | Output is correct |
26 | Correct | 457 ms | 4240 KB | Output is correct |
27 | Correct | 456 ms | 4216 KB | Output is correct |
28 | Correct | 512 ms | 4344 KB | Output is correct |
29 | Correct | 456 ms | 4472 KB | Output is correct |
30 | Correct | 11 ms | 4256 KB | Output is correct |
31 | Correct | 11 ms | 4352 KB | Output is correct |
32 | Correct | 10 ms | 4352 KB | Output is correct |
33 | Correct | 11 ms | 4352 KB | Output is correct |
34 | Correct | 11 ms | 4352 KB | Output is correct |
35 | Correct | 12 ms | 4352 KB | Output is correct |
36 | Correct | 11 ms | 4224 KB | Output is correct |
37 | Correct | 11 ms | 4352 KB | Output is correct |
38 | Correct | 11 ms | 4428 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 896 KB | Output is correct |
2 | Correct | 4 ms | 868 KB | Output is correct |
3 | Correct | 4 ms | 1024 KB | Output is correct |
4 | Correct | 4 ms | 896 KB | Output is correct |
5 | Correct | 4 ms | 896 KB | Output is correct |
6 | Correct | 6 ms | 896 KB | Output is correct |
7 | Correct | 6 ms | 896 KB | Output is correct |
8 | Correct | 6 ms | 896 KB | Output is correct |
9 | Correct | 6 ms | 896 KB | Output is correct |
10 | Correct | 7 ms | 896 KB | Output is correct |
11 | Correct | 4 ms | 896 KB | Output is correct |
12 | Correct | 4 ms | 896 KB | Output is correct |
13 | Correct | 4 ms | 896 KB | Output is correct |
14 | Correct | 4 ms | 896 KB | Output is correct |
15 | Correct | 5 ms | 896 KB | Output is correct |
16 | Correct | 4 ms | 768 KB | Output is correct |
17 | Correct | 3 ms | 896 KB | Output is correct |
18 | Correct | 3 ms | 768 KB | Output is correct |
19 | Correct | 3 ms | 896 KB | Output is correct |
20 | Correct | 4 ms | 896 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 4224 KB | Output is correct |
2 | Correct | 10 ms | 4224 KB | Output is correct |
3 | Correct | 10 ms | 4224 KB | Output is correct |
4 | Correct | 10 ms | 4224 KB | Output is correct |
5 | Correct | 10 ms | 4352 KB | Output is correct |
6 | Correct | 10 ms | 4352 KB | Output is correct |
7 | Correct | 11 ms | 4396 KB | Output is correct |
8 | Correct | 10 ms | 4352 KB | Output is correct |
9 | Correct | 10 ms | 4352 KB | Output is correct |
10 | Correct | 10 ms | 4224 KB | Output is correct |
11 | Correct | 10 ms | 4224 KB | Output is correct |
12 | Correct | 10 ms | 4224 KB | Output is correct |
13 | Correct | 10 ms | 4352 KB | Output is correct |
14 | Correct | 10 ms | 4352 KB | Output is correct |
15 | Correct | 10 ms | 4352 KB | Output is correct |
16 | Correct | 6 ms | 3072 KB | Output is correct |
17 | Correct | 6 ms | 3072 KB | Output is correct |
18 | Correct | 6 ms | 3072 KB | Output is correct |
19 | Correct | 6 ms | 3072 KB | Output is correct |
20 | Correct | 6 ms | 3072 KB | Output is correct |
21 | Correct | 207 ms | 4324 KB | Output is correct |
22 | Correct | 207 ms | 4272 KB | Output is correct |
23 | Correct | 182 ms | 4292 KB | Output is correct |
24 | Correct | 208 ms | 4444 KB | Output is correct |
25 | Correct | 216 ms | 4216 KB | Output is correct |
26 | Correct | 457 ms | 4240 KB | Output is correct |
27 | Correct | 456 ms | 4216 KB | Output is correct |
28 | Correct | 512 ms | 4344 KB | Output is correct |
29 | Correct | 456 ms | 4472 KB | Output is correct |
30 | Correct | 11 ms | 4256 KB | Output is correct |
31 | Correct | 11 ms | 4352 KB | Output is correct |
32 | Correct | 10 ms | 4352 KB | Output is correct |
33 | Correct | 11 ms | 4352 KB | Output is correct |
34 | Correct | 11 ms | 4352 KB | Output is correct |
35 | Correct | 12 ms | 4352 KB | Output is correct |
36 | Correct | 11 ms | 4224 KB | Output is correct |
37 | Correct | 11 ms | 4352 KB | Output is correct |
38 | Correct | 11 ms | 4428 KB | Output is correct |
39 | Correct | 4 ms | 896 KB | Output is correct |
40 | Correct | 4 ms | 868 KB | Output is correct |
41 | Correct | 4 ms | 1024 KB | Output is correct |
42 | Correct | 4 ms | 896 KB | Output is correct |
43 | Correct | 4 ms | 896 KB | Output is correct |
44 | Correct | 6 ms | 896 KB | Output is correct |
45 | Correct | 6 ms | 896 KB | Output is correct |
46 | Correct | 6 ms | 896 KB | Output is correct |
47 | Correct | 6 ms | 896 KB | Output is correct |
48 | Correct | 7 ms | 896 KB | Output is correct |
49 | Correct | 4 ms | 896 KB | Output is correct |
50 | Correct | 4 ms | 896 KB | Output is correct |
51 | Correct | 4 ms | 896 KB | Output is correct |
52 | Correct | 4 ms | 896 KB | Output is correct |
53 | Correct | 5 ms | 896 KB | Output is correct |
54 | Correct | 4 ms | 768 KB | Output is correct |
55 | Correct | 3 ms | 896 KB | Output is correct |
56 | Correct | 3 ms | 768 KB | Output is correct |
57 | Correct | 3 ms | 896 KB | Output is correct |
58 | Correct | 4 ms | 896 KB | Output is correct |
59 | Correct | 238 ms | 4344 KB | Output is correct |
60 | Correct | 203 ms | 4216 KB | Output is correct |
61 | Correct | 206 ms | 4216 KB | Output is correct |
62 | Correct | 229 ms | 4384 KB | Output is correct |
63 | Correct | 215 ms | 4216 KB | Output is correct |
64 | Correct | 531 ms | 4344 KB | Output is correct |
65 | Correct | 545 ms | 4436 KB | Output is correct |
66 | Correct | 543 ms | 4512 KB | Output is correct |
67 | Correct | 568 ms | 4472 KB | Output is correct |
68 | Correct | 576 ms | 4344 KB | Output is correct |
69 | Correct | 191 ms | 4452 KB | Output is correct |
70 | Correct | 196 ms | 4344 KB | Output is correct |
71 | Correct | 198 ms | 4316 KB | Output is correct |
72 | Correct | 201 ms | 4344 KB | Output is correct |
73 | Correct | 208 ms | 4344 KB | Output is correct |
74 | Correct | 65 ms | 3064 KB | Output is correct |
75 | Correct | 48 ms | 3064 KB | Output is correct |
76 | Correct | 51 ms | 3064 KB | Output is correct |
77 | Correct | 49 ms | 3064 KB | Output is correct |
78 | Correct | 53 ms | 3196 KB | Output is correct |