# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199231 | 2020-01-30T15:00:58 Z | anachor | Boat (APIO16_boat) | C++14 | 374 ms | 16248 KB |
#include<bits/stdc++.h> using namespace std; const int N = 1005, M = 1e9+7; int l[N], r[N]; int st[N], len[N]; typedef long long LL; LL dp[N][N]; LL sum[N][N]; LL power(LL a, LL p) { if (p==0) return 1; LL ans = power(a, p/2); ans = (ans * ans)%M; if (p%2) ans = (ans * a)%M; return ans; } LL f[N][N]; LL inv[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; map<int, int> mp; for (int i=1; i<=n; i++) { cin>>l[i]>>r[i]; mp[l[i]] = mp[r[i]+1] = 0; } int sz = 0; for (auto &pr: mp) { pr.second = ++sz; st[sz] = pr.first; } for (int i=1; i<=n; i++) inv[i] = power(i, M-2); for (int i=1; i<sz; i++) { len[i] = st[i+1] - st[i]; f[i][0] = 1; for (int j=1; j<=n; j++) { f[i][j] = (f[i][j-1]*(len[i]+j-1))%M; f[i][j] = (f[i][j]*inv[j])%M; } } dp[0][0] = 1; for (int i=0; i<=sz; i++) sum[0][i] = 1; long long ans = 0; for (int i=1; i<=n; i++) { int ll = mp[l[i]], rr = mp[r[i]+1]; for (int k=1; k<=sz; k++) { if (!(l[i] <= st[k] && st[k] <= r[i])) continue; int pos = 0; for (int j=i; j>=1; j--) { if (l[j] <= st[k] && st[k] <= r[j]) pos++; dp[i][k] = (dp[i][k] + f[k][pos] * sum[j-1][k-1])%M; } } for (int k=1; k<=sz; k++) sum[i][k] = (sum[i][k-1] + dp[i][k])%M; ans = (ans + sum[i][sz])%M; } cout<<ans<<endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 14072 KB | Output is correct |
2 | Correct | 25 ms | 14200 KB | Output is correct |
3 | Correct | 23 ms | 14200 KB | Output is correct |
4 | Correct | 24 ms | 14072 KB | Output is correct |
5 | Correct | 24 ms | 14072 KB | Output is correct |
6 | Correct | 24 ms | 14200 KB | Output is correct |
7 | Correct | 23 ms | 14200 KB | Output is correct |
8 | Correct | 23 ms | 14200 KB | Output is correct |
9 | Correct | 24 ms | 14200 KB | Output is correct |
10 | Correct | 25 ms | 14200 KB | Output is correct |
11 | Correct | 24 ms | 14200 KB | Output is correct |
12 | Correct | 23 ms | 14200 KB | Output is correct |
13 | Correct | 24 ms | 14200 KB | Output is correct |
14 | Correct | 23 ms | 14200 KB | Output is correct |
15 | Correct | 25 ms | 14200 KB | Output is correct |
16 | Correct | 12 ms | 6392 KB | Output is correct |
17 | Correct | 12 ms | 6652 KB | Output is correct |
18 | Correct | 12 ms | 6520 KB | Output is correct |
19 | Correct | 12 ms | 6648 KB | Output is correct |
20 | Correct | 12 ms | 6520 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 14072 KB | Output is correct |
2 | Correct | 25 ms | 14200 KB | Output is correct |
3 | Correct | 23 ms | 14200 KB | Output is correct |
4 | Correct | 24 ms | 14072 KB | Output is correct |
5 | Correct | 24 ms | 14072 KB | Output is correct |
6 | Correct | 24 ms | 14200 KB | Output is correct |
7 | Correct | 23 ms | 14200 KB | Output is correct |
8 | Correct | 23 ms | 14200 KB | Output is correct |
9 | Correct | 24 ms | 14200 KB | Output is correct |
10 | Correct | 25 ms | 14200 KB | Output is correct |
11 | Correct | 24 ms | 14200 KB | Output is correct |
12 | Correct | 23 ms | 14200 KB | Output is correct |
13 | Correct | 24 ms | 14200 KB | Output is correct |
14 | Correct | 23 ms | 14200 KB | Output is correct |
15 | Correct | 25 ms | 14200 KB | Output is correct |
16 | Correct | 12 ms | 6392 KB | Output is correct |
17 | Correct | 12 ms | 6652 KB | Output is correct |
18 | Correct | 12 ms | 6520 KB | Output is correct |
19 | Correct | 12 ms | 6648 KB | Output is correct |
20 | Correct | 12 ms | 6520 KB | Output is correct |
21 | Correct | 242 ms | 14584 KB | Output is correct |
22 | Correct | 240 ms | 14712 KB | Output is correct |
23 | Correct | 223 ms | 14584 KB | Output is correct |
24 | Correct | 229 ms | 14380 KB | Output is correct |
25 | Correct | 237 ms | 14564 KB | Output is correct |
26 | Correct | 305 ms | 14968 KB | Output is correct |
27 | Correct | 312 ms | 15096 KB | Output is correct |
28 | Correct | 323 ms | 14996 KB | Output is correct |
29 | Correct | 292 ms | 14840 KB | Output is correct |
30 | Correct | 26 ms | 14200 KB | Output is correct |
31 | Correct | 25 ms | 14200 KB | Output is correct |
32 | Correct | 27 ms | 14200 KB | Output is correct |
33 | Correct | 25 ms | 14200 KB | Output is correct |
34 | Correct | 25 ms | 14200 KB | Output is correct |
35 | Correct | 25 ms | 14200 KB | Output is correct |
36 | Correct | 29 ms | 14200 KB | Output is correct |
37 | Correct | 26 ms | 14072 KB | Output is correct |
38 | Correct | 25 ms | 14200 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 2296 KB | Output is correct |
2 | Correct | 9 ms | 2296 KB | Output is correct |
3 | Correct | 10 ms | 2428 KB | Output is correct |
4 | Correct | 8 ms | 2296 KB | Output is correct |
5 | Correct | 8 ms | 2428 KB | Output is correct |
6 | Correct | 9 ms | 2424 KB | Output is correct |
7 | Correct | 9 ms | 2424 KB | Output is correct |
8 | Correct | 9 ms | 2424 KB | Output is correct |
9 | Correct | 9 ms | 2296 KB | Output is correct |
10 | Correct | 9 ms | 2296 KB | Output is correct |
11 | Correct | 8 ms | 2300 KB | Output is correct |
12 | Correct | 8 ms | 2296 KB | Output is correct |
13 | Correct | 8 ms | 2296 KB | Output is correct |
14 | Correct | 8 ms | 2296 KB | Output is correct |
15 | Correct | 8 ms | 2296 KB | Output is correct |
16 | Correct | 7 ms | 1912 KB | Output is correct |
17 | Correct | 7 ms | 1784 KB | Output is correct |
18 | Correct | 7 ms | 1912 KB | Output is correct |
19 | Correct | 7 ms | 1784 KB | Output is correct |
20 | Correct | 7 ms | 1784 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 14072 KB | Output is correct |
2 | Correct | 25 ms | 14200 KB | Output is correct |
3 | Correct | 23 ms | 14200 KB | Output is correct |
4 | Correct | 24 ms | 14072 KB | Output is correct |
5 | Correct | 24 ms | 14072 KB | Output is correct |
6 | Correct | 24 ms | 14200 KB | Output is correct |
7 | Correct | 23 ms | 14200 KB | Output is correct |
8 | Correct | 23 ms | 14200 KB | Output is correct |
9 | Correct | 24 ms | 14200 KB | Output is correct |
10 | Correct | 25 ms | 14200 KB | Output is correct |
11 | Correct | 24 ms | 14200 KB | Output is correct |
12 | Correct | 23 ms | 14200 KB | Output is correct |
13 | Correct | 24 ms | 14200 KB | Output is correct |
14 | Correct | 23 ms | 14200 KB | Output is correct |
15 | Correct | 25 ms | 14200 KB | Output is correct |
16 | Correct | 12 ms | 6392 KB | Output is correct |
17 | Correct | 12 ms | 6652 KB | Output is correct |
18 | Correct | 12 ms | 6520 KB | Output is correct |
19 | Correct | 12 ms | 6648 KB | Output is correct |
20 | Correct | 12 ms | 6520 KB | Output is correct |
21 | Correct | 242 ms | 14584 KB | Output is correct |
22 | Correct | 240 ms | 14712 KB | Output is correct |
23 | Correct | 223 ms | 14584 KB | Output is correct |
24 | Correct | 229 ms | 14380 KB | Output is correct |
25 | Correct | 237 ms | 14564 KB | Output is correct |
26 | Correct | 305 ms | 14968 KB | Output is correct |
27 | Correct | 312 ms | 15096 KB | Output is correct |
28 | Correct | 323 ms | 14996 KB | Output is correct |
29 | Correct | 292 ms | 14840 KB | Output is correct |
30 | Correct | 26 ms | 14200 KB | Output is correct |
31 | Correct | 25 ms | 14200 KB | Output is correct |
32 | Correct | 27 ms | 14200 KB | Output is correct |
33 | Correct | 25 ms | 14200 KB | Output is correct |
34 | Correct | 25 ms | 14200 KB | Output is correct |
35 | Correct | 25 ms | 14200 KB | Output is correct |
36 | Correct | 29 ms | 14200 KB | Output is correct |
37 | Correct | 26 ms | 14072 KB | Output is correct |
38 | Correct | 25 ms | 14200 KB | Output is correct |
39 | Correct | 8 ms | 2296 KB | Output is correct |
40 | Correct | 9 ms | 2296 KB | Output is correct |
41 | Correct | 10 ms | 2428 KB | Output is correct |
42 | Correct | 8 ms | 2296 KB | Output is correct |
43 | Correct | 8 ms | 2428 KB | Output is correct |
44 | Correct | 9 ms | 2424 KB | Output is correct |
45 | Correct | 9 ms | 2424 KB | Output is correct |
46 | Correct | 9 ms | 2424 KB | Output is correct |
47 | Correct | 9 ms | 2296 KB | Output is correct |
48 | Correct | 9 ms | 2296 KB | Output is correct |
49 | Correct | 8 ms | 2300 KB | Output is correct |
50 | Correct | 8 ms | 2296 KB | Output is correct |
51 | Correct | 8 ms | 2296 KB | Output is correct |
52 | Correct | 8 ms | 2296 KB | Output is correct |
53 | Correct | 8 ms | 2296 KB | Output is correct |
54 | Correct | 7 ms | 1912 KB | Output is correct |
55 | Correct | 7 ms | 1784 KB | Output is correct |
56 | Correct | 7 ms | 1912 KB | Output is correct |
57 | Correct | 7 ms | 1784 KB | Output is correct |
58 | Correct | 7 ms | 1784 KB | Output is correct |
59 | Correct | 283 ms | 15224 KB | Output is correct |
60 | Correct | 255 ms | 15224 KB | Output is correct |
61 | Correct | 244 ms | 15228 KB | Output is correct |
62 | Correct | 273 ms | 15224 KB | Output is correct |
63 | Correct | 263 ms | 15352 KB | Output is correct |
64 | Correct | 369 ms | 16120 KB | Output is correct |
65 | Correct | 363 ms | 16124 KB | Output is correct |
66 | Correct | 374 ms | 16128 KB | Output is correct |
67 | Correct | 352 ms | 16120 KB | Output is correct |
68 | Correct | 361 ms | 16248 KB | Output is correct |
69 | Correct | 196 ms | 15352 KB | Output is correct |
70 | Correct | 193 ms | 15352 KB | Output is correct |
71 | Correct | 198 ms | 15384 KB | Output is correct |
72 | Correct | 199 ms | 15352 KB | Output is correct |
73 | Correct | 199 ms | 15352 KB | Output is correct |
74 | Correct | 52 ms | 6776 KB | Output is correct |
75 | Correct | 50 ms | 6776 KB | Output is correct |
76 | Correct | 54 ms | 6776 KB | Output is correct |
77 | Correct | 52 ms | 6776 KB | Output is correct |
78 | Correct | 56 ms | 6780 KB | Output is correct |