# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
346704 | 2021-01-10T18:39:08 Z | YJU | Boat (APIO16_boat) | C++14 | 292 ms | 492 KB |
#include <cstdio> #include <algorithm> typedef long long ll; const int MAXN = 500; const ll MOD = 1000000007LL; using namespace std; int top, a[MAXN+1], b[MAXN+1], l[MAXN+1], r[MAXN+1], h[2*MAXN+1], g[MAXN+1]; ll inv[MAXN+1], C[MAXN+1]; int main() { int N; scanf("%d", &N); inv[1] = 1; for (int i = 2; i <= N; ++i) inv[i] = (MOD-MOD/i)*inv[MOD%i]%MOD; for (int i = 1; i <= N; ++i) { scanf("%d %d", &a[i], &b[i]); h[2*i-1] = a[i]; h[2*i] = b[i]+1; } sort(h+1, h+2*N+1); top = unique(h+1, h+2*N+1)-h-1; for (int i = 1; i <= N; ++i) { // [l, r) l[i] = lower_bound(h+1, h+1+top, a[i])-h; r[i] = lower_bound(h+1, h+1+top, b[i]+1)-h; } g[0] = 1; C[0] = 1; for (int j = 1; j < top; ++j) { int L = h[j+1]-h[j]; for (int i = 1; i <= N; ++i) C[i] = C[i-1]*(L+i-1) %MOD * inv[i] %MOD; for (int i = N; i >= 1; --i) { if (l[i]<=j && j+1<=r[i]) { ll f = 0, m = 1, c = L; // m: p+1~i號學校有多少能選區間j for (int p = i-1; p >= 0; --p) { f = (f + c*g[p]) % MOD; if (l[p]<=j && j+1<=r[p]) c = C[++m]; } g[i] = (g[i]+f) % MOD; } } } int ans = 0; for (int i = 1; i <= N; ++i) ans = (ans+g[i]) % MOD; printf("%d", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 364 KB | Output is correct |
2 | Correct | 9 ms | 364 KB | Output is correct |
3 | Correct | 9 ms | 364 KB | Output is correct |
4 | Correct | 9 ms | 364 KB | Output is correct |
5 | Correct | 9 ms | 364 KB | Output is correct |
6 | Correct | 8 ms | 364 KB | Output is correct |
7 | Correct | 8 ms | 364 KB | Output is correct |
8 | Correct | 8 ms | 364 KB | Output is correct |
9 | Correct | 8 ms | 364 KB | Output is correct |
10 | Correct | 8 ms | 364 KB | Output is correct |
11 | Correct | 8 ms | 364 KB | Output is correct |
12 | Correct | 9 ms | 364 KB | Output is correct |
13 | Correct | 9 ms | 364 KB | Output is correct |
14 | Correct | 8 ms | 364 KB | Output is correct |
15 | Correct | 9 ms | 492 KB | Output is correct |
16 | Correct | 3 ms | 364 KB | Output is correct |
17 | Correct | 3 ms | 364 KB | Output is correct |
18 | Correct | 3 ms | 364 KB | Output is correct |
19 | Correct | 3 ms | 364 KB | Output is correct |
20 | Correct | 3 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 364 KB | Output is correct |
2 | Correct | 9 ms | 364 KB | Output is correct |
3 | Correct | 9 ms | 364 KB | Output is correct |
4 | Correct | 9 ms | 364 KB | Output is correct |
5 | Correct | 9 ms | 364 KB | Output is correct |
6 | Correct | 8 ms | 364 KB | Output is correct |
7 | Correct | 8 ms | 364 KB | Output is correct |
8 | Correct | 8 ms | 364 KB | Output is correct |
9 | Correct | 8 ms | 364 KB | Output is correct |
10 | Correct | 8 ms | 364 KB | Output is correct |
11 | Correct | 8 ms | 364 KB | Output is correct |
12 | Correct | 9 ms | 364 KB | Output is correct |
13 | Correct | 9 ms | 364 KB | Output is correct |
14 | Correct | 8 ms | 364 KB | Output is correct |
15 | Correct | 9 ms | 492 KB | Output is correct |
16 | Correct | 3 ms | 364 KB | Output is correct |
17 | Correct | 3 ms | 364 KB | Output is correct |
18 | Correct | 3 ms | 364 KB | Output is correct |
19 | Correct | 3 ms | 364 KB | Output is correct |
20 | Correct | 3 ms | 364 KB | Output is correct |
21 | Correct | 193 ms | 492 KB | Output is correct |
22 | Correct | 185 ms | 492 KB | Output is correct |
23 | Correct | 175 ms | 380 KB | Output is correct |
24 | Correct | 183 ms | 380 KB | Output is correct |
25 | Correct | 182 ms | 364 KB | Output is correct |
26 | Correct | 252 ms | 364 KB | Output is correct |
27 | Correct | 259 ms | 364 KB | Output is correct |
28 | Correct | 252 ms | 492 KB | Output is correct |
29 | Correct | 250 ms | 364 KB | Output is correct |
30 | Correct | 10 ms | 364 KB | Output is correct |
31 | Correct | 9 ms | 364 KB | Output is correct |
32 | Correct | 9 ms | 364 KB | Output is correct |
33 | Correct | 9 ms | 364 KB | Output is correct |
34 | Correct | 9 ms | 364 KB | Output is correct |
35 | Correct | 10 ms | 364 KB | Output is correct |
36 | Correct | 10 ms | 364 KB | Output is correct |
37 | Correct | 10 ms | 364 KB | Output is correct |
38 | Correct | 10 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 364 KB | Output is correct |
2 | Correct | 2 ms | 364 KB | Output is correct |
3 | Correct | 2 ms | 364 KB | Output is correct |
4 | Correct | 2 ms | 364 KB | Output is correct |
5 | Correct | 3 ms | 364 KB | Output is correct |
6 | Correct | 3 ms | 364 KB | Output is correct |
7 | Correct | 3 ms | 364 KB | Output is correct |
8 | Correct | 3 ms | 364 KB | Output is correct |
9 | Correct | 3 ms | 364 KB | Output is correct |
10 | Correct | 3 ms | 364 KB | Output is correct |
11 | Correct | 2 ms | 364 KB | Output is correct |
12 | Correct | 2 ms | 364 KB | Output is correct |
13 | Correct | 2 ms | 364 KB | Output is correct |
14 | Correct | 2 ms | 364 KB | Output is correct |
15 | Correct | 2 ms | 364 KB | Output is correct |
16 | Correct | 2 ms | 364 KB | Output is correct |
17 | Correct | 2 ms | 364 KB | Output is correct |
18 | Correct | 2 ms | 364 KB | Output is correct |
19 | Correct | 2 ms | 364 KB | Output is correct |
20 | Correct | 2 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 364 KB | Output is correct |
2 | Correct | 9 ms | 364 KB | Output is correct |
3 | Correct | 9 ms | 364 KB | Output is correct |
4 | Correct | 9 ms | 364 KB | Output is correct |
5 | Correct | 9 ms | 364 KB | Output is correct |
6 | Correct | 8 ms | 364 KB | Output is correct |
7 | Correct | 8 ms | 364 KB | Output is correct |
8 | Correct | 8 ms | 364 KB | Output is correct |
9 | Correct | 8 ms | 364 KB | Output is correct |
10 | Correct | 8 ms | 364 KB | Output is correct |
11 | Correct | 8 ms | 364 KB | Output is correct |
12 | Correct | 9 ms | 364 KB | Output is correct |
13 | Correct | 9 ms | 364 KB | Output is correct |
14 | Correct | 8 ms | 364 KB | Output is correct |
15 | Correct | 9 ms | 492 KB | Output is correct |
16 | Correct | 3 ms | 364 KB | Output is correct |
17 | Correct | 3 ms | 364 KB | Output is correct |
18 | Correct | 3 ms | 364 KB | Output is correct |
19 | Correct | 3 ms | 364 KB | Output is correct |
20 | Correct | 3 ms | 364 KB | Output is correct |
21 | Correct | 193 ms | 492 KB | Output is correct |
22 | Correct | 185 ms | 492 KB | Output is correct |
23 | Correct | 175 ms | 380 KB | Output is correct |
24 | Correct | 183 ms | 380 KB | Output is correct |
25 | Correct | 182 ms | 364 KB | Output is correct |
26 | Correct | 252 ms | 364 KB | Output is correct |
27 | Correct | 259 ms | 364 KB | Output is correct |
28 | Correct | 252 ms | 492 KB | Output is correct |
29 | Correct | 250 ms | 364 KB | Output is correct |
30 | Correct | 10 ms | 364 KB | Output is correct |
31 | Correct | 9 ms | 364 KB | Output is correct |
32 | Correct | 9 ms | 364 KB | Output is correct |
33 | Correct | 9 ms | 364 KB | Output is correct |
34 | Correct | 9 ms | 364 KB | Output is correct |
35 | Correct | 10 ms | 364 KB | Output is correct |
36 | Correct | 10 ms | 364 KB | Output is correct |
37 | Correct | 10 ms | 364 KB | Output is correct |
38 | Correct | 10 ms | 364 KB | Output is correct |
39 | Correct | 2 ms | 364 KB | Output is correct |
40 | Correct | 2 ms | 364 KB | Output is correct |
41 | Correct | 2 ms | 364 KB | Output is correct |
42 | Correct | 2 ms | 364 KB | Output is correct |
43 | Correct | 3 ms | 364 KB | Output is correct |
44 | Correct | 3 ms | 364 KB | Output is correct |
45 | Correct | 3 ms | 364 KB | Output is correct |
46 | Correct | 3 ms | 364 KB | Output is correct |
47 | Correct | 3 ms | 364 KB | Output is correct |
48 | Correct | 3 ms | 364 KB | Output is correct |
49 | Correct | 2 ms | 364 KB | Output is correct |
50 | Correct | 2 ms | 364 KB | Output is correct |
51 | Correct | 2 ms | 364 KB | Output is correct |
52 | Correct | 2 ms | 364 KB | Output is correct |
53 | Correct | 2 ms | 364 KB | Output is correct |
54 | Correct | 2 ms | 364 KB | Output is correct |
55 | Correct | 2 ms | 364 KB | Output is correct |
56 | Correct | 2 ms | 364 KB | Output is correct |
57 | Correct | 2 ms | 364 KB | Output is correct |
58 | Correct | 2 ms | 364 KB | Output is correct |
59 | Correct | 206 ms | 364 KB | Output is correct |
60 | Correct | 198 ms | 364 KB | Output is correct |
61 | Correct | 186 ms | 492 KB | Output is correct |
62 | Correct | 205 ms | 364 KB | Output is correct |
63 | Correct | 203 ms | 384 KB | Output is correct |
64 | Correct | 291 ms | 364 KB | Output is correct |
65 | Correct | 290 ms | 492 KB | Output is correct |
66 | Correct | 289 ms | 492 KB | Output is correct |
67 | Correct | 292 ms | 492 KB | Output is correct |
68 | Correct | 292 ms | 492 KB | Output is correct |
69 | Correct | 158 ms | 364 KB | Output is correct |
70 | Correct | 154 ms | 364 KB | Output is correct |
71 | Correct | 153 ms | 492 KB | Output is correct |
72 | Correct | 165 ms | 364 KB | Output is correct |
73 | Correct | 165 ms | 384 KB | Output is correct |
74 | Correct | 40 ms | 364 KB | Output is correct |
75 | Correct | 38 ms | 364 KB | Output is correct |
76 | Correct | 40 ms | 364 KB | Output is correct |
77 | Correct | 40 ms | 364 KB | Output is correct |
78 | Correct | 45 ms | 364 KB | Output is correct |