# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
109550 | 2019-05-07T04:00:15 Z | PeppaPig | Boat (APIO16_boat) | C++14 | 871 ms | 4508 KB |
#include <bits/stdc++.h> #define long long long using namespace std; const int N = 1005; const int M = 1e9+7; long fac[N], inv[N]; long modpow(long a, long b) { long ret = 1; for( ; b; b >>= 1) { if(b & 1) ret = (ret * a) % M; a = (a * a) % M; } return ret; } void pre_process() { fac[0] = inv[0] = 1; for(int i = 1; i < N; i++) fac[i] = (fac[i-1] * i) % M; for(int i = 1; i < N; i++) inv[i] = modpow(fac[i], M-2); } long ncr(int n, int r) { return fac[n] * (inv[r] * inv[n-r] % M) % M; } int n, a[N], b[N]; long dp[N][N]; vector<int> coord; int main() { pre_process(); scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d %d", a+i, b+i); coord.emplace_back(a[i]); coord.emplace_back(++b[i]); } sort(coord.begin(), coord.end()); coord.resize(unique(coord.begin(), coord.end()) - coord.begin()); for(int i = 1; i <= n; i++) { a[i] = lower_bound(coord.begin(), coord.end(), a[i]) - coord.begin() + 1; b[i] = lower_bound(coord.begin(), coord.end(), b[i]) - coord.begin() + 1; } for(int i = 0; i < coord.size(); i++) dp[0][i] = 1; for(int i = 1; i <= n; i++) { for(int j = a[i]; j < b[i]; j++) { long p = coord[j] - coord[j-1], cnt = 1; for(int k = i-1; ~k; k--) { dp[i][j] = (dp[i][j] + (p * dp[k][j-1]) % M) % M; if(a[k] <= j && j < b[k]) { ++cnt; p = ncr(coord[j] - coord[j-1] + cnt - 1, cnt); } } } for(int j = 1; j < coord.size(); j++) dp[i][j] = (dp[i][j] + dp[i][j-1]) % M; } long ans = 0; for(int i = 1; i <= n; i++) ans = (ans + dp[i][coord.size()-1]) % M; printf("%lld\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 4352 KB | Output is correct |
2 | Correct | 12 ms | 4224 KB | Output is correct |
3 | Correct | 13 ms | 4224 KB | Output is correct |
4 | Correct | 12 ms | 4224 KB | Output is correct |
5 | Correct | 13 ms | 4224 KB | Output is correct |
6 | Correct | 13 ms | 4344 KB | Output is correct |
7 | Correct | 13 ms | 4352 KB | Output is correct |
8 | Correct | 13 ms | 4224 KB | Output is correct |
9 | Correct | 13 ms | 4224 KB | Output is correct |
10 | Correct | 13 ms | 4352 KB | Output is correct |
11 | Correct | 14 ms | 4352 KB | Output is correct |
12 | Correct | 12 ms | 4224 KB | Output is correct |
13 | Correct | 12 ms | 4352 KB | Output is correct |
14 | Correct | 13 ms | 4224 KB | Output is correct |
15 | Correct | 15 ms | 4352 KB | Output is correct |
16 | Correct | 8 ms | 3072 KB | Output is correct |
17 | Correct | 7 ms | 3072 KB | Output is correct |
18 | Correct | 8 ms | 3072 KB | Output is correct |
19 | Correct | 8 ms | 3072 KB | Output is correct |
20 | Correct | 7 ms | 3072 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 4352 KB | Output is correct |
2 | Correct | 12 ms | 4224 KB | Output is correct |
3 | Correct | 13 ms | 4224 KB | Output is correct |
4 | Correct | 12 ms | 4224 KB | Output is correct |
5 | Correct | 13 ms | 4224 KB | Output is correct |
6 | Correct | 13 ms | 4344 KB | Output is correct |
7 | Correct | 13 ms | 4352 KB | Output is correct |
8 | Correct | 13 ms | 4224 KB | Output is correct |
9 | Correct | 13 ms | 4224 KB | Output is correct |
10 | Correct | 13 ms | 4352 KB | Output is correct |
11 | Correct | 14 ms | 4352 KB | Output is correct |
12 | Correct | 12 ms | 4224 KB | Output is correct |
13 | Correct | 12 ms | 4352 KB | Output is correct |
14 | Correct | 13 ms | 4224 KB | Output is correct |
15 | Correct | 15 ms | 4352 KB | Output is correct |
16 | Correct | 8 ms | 3072 KB | Output is correct |
17 | Correct | 7 ms | 3072 KB | Output is correct |
18 | Correct | 8 ms | 3072 KB | Output is correct |
19 | Correct | 8 ms | 3072 KB | Output is correct |
20 | Correct | 7 ms | 3072 KB | Output is correct |
21 | Correct | 507 ms | 4508 KB | Output is correct |
22 | Correct | 547 ms | 4264 KB | Output is correct |
23 | Correct | 426 ms | 4344 KB | Output is correct |
24 | Correct | 584 ms | 4304 KB | Output is correct |
25 | Correct | 751 ms | 4316 KB | Output is correct |
26 | Correct | 871 ms | 4492 KB | Output is correct |
27 | Correct | 682 ms | 4352 KB | Output is correct |
28 | Correct | 836 ms | 4472 KB | Output is correct |
29 | Correct | 672 ms | 4312 KB | Output is correct |
30 | Correct | 17 ms | 4224 KB | Output is correct |
31 | Correct | 12 ms | 4352 KB | Output is correct |
32 | Correct | 17 ms | 4224 KB | Output is correct |
33 | Correct | 14 ms | 4224 KB | Output is correct |
34 | Correct | 12 ms | 4352 KB | Output is correct |
35 | Correct | 17 ms | 4352 KB | Output is correct |
36 | Correct | 14 ms | 4224 KB | Output is correct |
37 | Correct | 19 ms | 4224 KB | Output is correct |
38 | Correct | 21 ms | 4344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 4 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 4352 KB | Output is correct |
2 | Correct | 12 ms | 4224 KB | Output is correct |
3 | Correct | 13 ms | 4224 KB | Output is correct |
4 | Correct | 12 ms | 4224 KB | Output is correct |
5 | Correct | 13 ms | 4224 KB | Output is correct |
6 | Correct | 13 ms | 4344 KB | Output is correct |
7 | Correct | 13 ms | 4352 KB | Output is correct |
8 | Correct | 13 ms | 4224 KB | Output is correct |
9 | Correct | 13 ms | 4224 KB | Output is correct |
10 | Correct | 13 ms | 4352 KB | Output is correct |
11 | Correct | 14 ms | 4352 KB | Output is correct |
12 | Correct | 12 ms | 4224 KB | Output is correct |
13 | Correct | 12 ms | 4352 KB | Output is correct |
14 | Correct | 13 ms | 4224 KB | Output is correct |
15 | Correct | 15 ms | 4352 KB | Output is correct |
16 | Correct | 8 ms | 3072 KB | Output is correct |
17 | Correct | 7 ms | 3072 KB | Output is correct |
18 | Correct | 8 ms | 3072 KB | Output is correct |
19 | Correct | 8 ms | 3072 KB | Output is correct |
20 | Correct | 7 ms | 3072 KB | Output is correct |
21 | Correct | 507 ms | 4508 KB | Output is correct |
22 | Correct | 547 ms | 4264 KB | Output is correct |
23 | Correct | 426 ms | 4344 KB | Output is correct |
24 | Correct | 584 ms | 4304 KB | Output is correct |
25 | Correct | 751 ms | 4316 KB | Output is correct |
26 | Correct | 871 ms | 4492 KB | Output is correct |
27 | Correct | 682 ms | 4352 KB | Output is correct |
28 | Correct | 836 ms | 4472 KB | Output is correct |
29 | Correct | 672 ms | 4312 KB | Output is correct |
30 | Correct | 17 ms | 4224 KB | Output is correct |
31 | Correct | 12 ms | 4352 KB | Output is correct |
32 | Correct | 17 ms | 4224 KB | Output is correct |
33 | Correct | 14 ms | 4224 KB | Output is correct |
34 | Correct | 12 ms | 4352 KB | Output is correct |
35 | Correct | 17 ms | 4352 KB | Output is correct |
36 | Correct | 14 ms | 4224 KB | Output is correct |
37 | Correct | 19 ms | 4224 KB | Output is correct |
38 | Correct | 21 ms | 4344 KB | Output is correct |
39 | Runtime error | 4 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
40 | Halted | 0 ms | 0 KB | - |