# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
376374 |
2021-03-11T10:31:57 Z |
shivensinha4 |
Boat (APIO16_boat) |
C++17 |
|
1811 ms |
620 KB |
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
#define endl '\n'
const ll mod = 1e9+7;
const ll MAXN = 500;
ll numInv[MAXN+10], facInv[MAXN+10], fac[MAXN+10];
void pre() {
numInv[0] = numInv[1] = 1;
for (int i = 2; i <= MAXN; i++) numInv[i] = numInv[mod % i] * (mod - mod / i) % mod;
facInv[0] = facInv[1] = 1;
for (int i = 2; i <= MAXN; i++) facInv[i] = (numInv[i] * facInv[i - 1]) % mod;
fac[0] = 1;
for (int i = 1; i <= MAXN; i++) fac[i] = (fac[i - 1] * i) % mod;
}
ll nCr(ll n, ll r) {
return ((fac[n] * facInv[r]) % mod * facInv[n - r]) % mod;
}
ll choose[MAXN+1], dp[2][MAXN+1];
int main() {
#ifdef mlocal
freopen("test.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
memset(choose, 0, sizeof(choose)); memset(dp, 0, sizeof(dp));
pre();
int n; cin >> n;
vector<ii> lt(n);
vi raw(2*n);
for_(i, 0, n) {
cin >> lt[i][0] >> lt[i][1];
lt[i][1]++;
raw[2*i] = lt[i][0], raw[2*i+1] = lt[i][1];
}
sort(raw.begin(), raw.end());
raw.resize(unique(raw.begin(), raw.end()) - raw.begin());
int ns = raw.size()-1;
int cs = 0; ll len, val;
dp[1][n] = 1;
for (int s = ns-1; s >= 0; s--) {
choose[0] = 1;
len = raw[s+1]-raw[s];
for_(r, 1, n+1) {
choose[r] = 0;
val = 1;
for_(t, 1, r+1) {
if (t > len) val = 0;
else val = ((val * (len-t+1)) % mod) % mod;
choose[r] += (((nCr(r-1, t-1) * val) % mod) * facInv[t]) % mod;
if (choose[r] >= mod) choose[r] -= mod;
}
}
dp[cs][n] = 1;
for_(i, 0, n) {
dp[cs][i] = dp[1-cs][i];
int ct = raw[s] >= lt[i][0] and raw[s+1] <= lt[i][1];
if (ct) {
for_(j, i+1, n+1) {
dp[cs][i] += (choose[ct] * dp[1-cs][j]) % mod;
if (dp[cs][i] >= mod) dp[cs][i] -= mod;
if (j < n and raw[s] >= lt[j][0] and raw[s+1] <= lt[j][1]) ct++;
}
}
}
cs = 1-cs;
}
ll ans = 0;
for_(i, 0, n) {
ans += dp[1-cs][i];
if (ans >= mod) ans -= mod;
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
744 ms |
492 KB |
Output is correct |
2 |
Correct |
754 ms |
492 KB |
Output is correct |
3 |
Correct |
766 ms |
364 KB |
Output is correct |
4 |
Correct |
752 ms |
492 KB |
Output is correct |
5 |
Correct |
760 ms |
440 KB |
Output is correct |
6 |
Correct |
768 ms |
492 KB |
Output is correct |
7 |
Correct |
763 ms |
492 KB |
Output is correct |
8 |
Correct |
778 ms |
440 KB |
Output is correct |
9 |
Correct |
751 ms |
492 KB |
Output is correct |
10 |
Correct |
756 ms |
440 KB |
Output is correct |
11 |
Correct |
759 ms |
440 KB |
Output is correct |
12 |
Correct |
755 ms |
492 KB |
Output is correct |
13 |
Correct |
751 ms |
364 KB |
Output is correct |
14 |
Correct |
750 ms |
364 KB |
Output is correct |
15 |
Correct |
755 ms |
492 KB |
Output is correct |
16 |
Correct |
131 ms |
364 KB |
Output is correct |
17 |
Correct |
146 ms |
440 KB |
Output is correct |
18 |
Correct |
141 ms |
492 KB |
Output is correct |
19 |
Correct |
142 ms |
364 KB |
Output is correct |
20 |
Correct |
139 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
744 ms |
492 KB |
Output is correct |
2 |
Correct |
754 ms |
492 KB |
Output is correct |
3 |
Correct |
766 ms |
364 KB |
Output is correct |
4 |
Correct |
752 ms |
492 KB |
Output is correct |
5 |
Correct |
760 ms |
440 KB |
Output is correct |
6 |
Correct |
768 ms |
492 KB |
Output is correct |
7 |
Correct |
763 ms |
492 KB |
Output is correct |
8 |
Correct |
778 ms |
440 KB |
Output is correct |
9 |
Correct |
751 ms |
492 KB |
Output is correct |
10 |
Correct |
756 ms |
440 KB |
Output is correct |
11 |
Correct |
759 ms |
440 KB |
Output is correct |
12 |
Correct |
755 ms |
492 KB |
Output is correct |
13 |
Correct |
751 ms |
364 KB |
Output is correct |
14 |
Correct |
750 ms |
364 KB |
Output is correct |
15 |
Correct |
755 ms |
492 KB |
Output is correct |
16 |
Correct |
131 ms |
364 KB |
Output is correct |
17 |
Correct |
146 ms |
440 KB |
Output is correct |
18 |
Correct |
141 ms |
492 KB |
Output is correct |
19 |
Correct |
142 ms |
364 KB |
Output is correct |
20 |
Correct |
139 ms |
492 KB |
Output is correct |
21 |
Correct |
214 ms |
512 KB |
Output is correct |
22 |
Correct |
221 ms |
364 KB |
Output is correct |
23 |
Correct |
202 ms |
376 KB |
Output is correct |
24 |
Correct |
209 ms |
364 KB |
Output is correct |
25 |
Correct |
225 ms |
364 KB |
Output is correct |
26 |
Correct |
268 ms |
364 KB |
Output is correct |
27 |
Correct |
291 ms |
492 KB |
Output is correct |
28 |
Correct |
273 ms |
492 KB |
Output is correct |
29 |
Correct |
276 ms |
492 KB |
Output is correct |
30 |
Correct |
712 ms |
492 KB |
Output is correct |
31 |
Correct |
723 ms |
440 KB |
Output is correct |
32 |
Correct |
729 ms |
440 KB |
Output is correct |
33 |
Correct |
753 ms |
364 KB |
Output is correct |
34 |
Correct |
736 ms |
492 KB |
Output is correct |
35 |
Correct |
724 ms |
492 KB |
Output is correct |
36 |
Correct |
705 ms |
492 KB |
Output is correct |
37 |
Correct |
718 ms |
620 KB |
Output is correct |
38 |
Correct |
703 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
364 KB |
Output is correct |
2 |
Correct |
14 ms |
364 KB |
Output is correct |
3 |
Correct |
14 ms |
364 KB |
Output is correct |
4 |
Correct |
16 ms |
364 KB |
Output is correct |
5 |
Correct |
14 ms |
364 KB |
Output is correct |
6 |
Correct |
15 ms |
364 KB |
Output is correct |
7 |
Correct |
15 ms |
364 KB |
Output is correct |
8 |
Correct |
15 ms |
364 KB |
Output is correct |
9 |
Correct |
15 ms |
364 KB |
Output is correct |
10 |
Correct |
15 ms |
364 KB |
Output is correct |
11 |
Correct |
15 ms |
364 KB |
Output is correct |
12 |
Correct |
14 ms |
492 KB |
Output is correct |
13 |
Correct |
15 ms |
364 KB |
Output is correct |
14 |
Correct |
14 ms |
364 KB |
Output is correct |
15 |
Correct |
15 ms |
364 KB |
Output is correct |
16 |
Correct |
7 ms |
364 KB |
Output is correct |
17 |
Correct |
7 ms |
364 KB |
Output is correct |
18 |
Correct |
7 ms |
364 KB |
Output is correct |
19 |
Correct |
7 ms |
364 KB |
Output is correct |
20 |
Correct |
7 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
744 ms |
492 KB |
Output is correct |
2 |
Correct |
754 ms |
492 KB |
Output is correct |
3 |
Correct |
766 ms |
364 KB |
Output is correct |
4 |
Correct |
752 ms |
492 KB |
Output is correct |
5 |
Correct |
760 ms |
440 KB |
Output is correct |
6 |
Correct |
768 ms |
492 KB |
Output is correct |
7 |
Correct |
763 ms |
492 KB |
Output is correct |
8 |
Correct |
778 ms |
440 KB |
Output is correct |
9 |
Correct |
751 ms |
492 KB |
Output is correct |
10 |
Correct |
756 ms |
440 KB |
Output is correct |
11 |
Correct |
759 ms |
440 KB |
Output is correct |
12 |
Correct |
755 ms |
492 KB |
Output is correct |
13 |
Correct |
751 ms |
364 KB |
Output is correct |
14 |
Correct |
750 ms |
364 KB |
Output is correct |
15 |
Correct |
755 ms |
492 KB |
Output is correct |
16 |
Correct |
131 ms |
364 KB |
Output is correct |
17 |
Correct |
146 ms |
440 KB |
Output is correct |
18 |
Correct |
141 ms |
492 KB |
Output is correct |
19 |
Correct |
142 ms |
364 KB |
Output is correct |
20 |
Correct |
139 ms |
492 KB |
Output is correct |
21 |
Correct |
214 ms |
512 KB |
Output is correct |
22 |
Correct |
221 ms |
364 KB |
Output is correct |
23 |
Correct |
202 ms |
376 KB |
Output is correct |
24 |
Correct |
209 ms |
364 KB |
Output is correct |
25 |
Correct |
225 ms |
364 KB |
Output is correct |
26 |
Correct |
268 ms |
364 KB |
Output is correct |
27 |
Correct |
291 ms |
492 KB |
Output is correct |
28 |
Correct |
273 ms |
492 KB |
Output is correct |
29 |
Correct |
276 ms |
492 KB |
Output is correct |
30 |
Correct |
712 ms |
492 KB |
Output is correct |
31 |
Correct |
723 ms |
440 KB |
Output is correct |
32 |
Correct |
729 ms |
440 KB |
Output is correct |
33 |
Correct |
753 ms |
364 KB |
Output is correct |
34 |
Correct |
736 ms |
492 KB |
Output is correct |
35 |
Correct |
724 ms |
492 KB |
Output is correct |
36 |
Correct |
705 ms |
492 KB |
Output is correct |
37 |
Correct |
718 ms |
620 KB |
Output is correct |
38 |
Correct |
703 ms |
492 KB |
Output is correct |
39 |
Correct |
15 ms |
364 KB |
Output is correct |
40 |
Correct |
14 ms |
364 KB |
Output is correct |
41 |
Correct |
14 ms |
364 KB |
Output is correct |
42 |
Correct |
16 ms |
364 KB |
Output is correct |
43 |
Correct |
14 ms |
364 KB |
Output is correct |
44 |
Correct |
15 ms |
364 KB |
Output is correct |
45 |
Correct |
15 ms |
364 KB |
Output is correct |
46 |
Correct |
15 ms |
364 KB |
Output is correct |
47 |
Correct |
15 ms |
364 KB |
Output is correct |
48 |
Correct |
15 ms |
364 KB |
Output is correct |
49 |
Correct |
15 ms |
364 KB |
Output is correct |
50 |
Correct |
14 ms |
492 KB |
Output is correct |
51 |
Correct |
15 ms |
364 KB |
Output is correct |
52 |
Correct |
14 ms |
364 KB |
Output is correct |
53 |
Correct |
15 ms |
364 KB |
Output is correct |
54 |
Correct |
7 ms |
364 KB |
Output is correct |
55 |
Correct |
7 ms |
364 KB |
Output is correct |
56 |
Correct |
7 ms |
364 KB |
Output is correct |
57 |
Correct |
7 ms |
364 KB |
Output is correct |
58 |
Correct |
7 ms |
364 KB |
Output is correct |
59 |
Correct |
1707 ms |
440 KB |
Output is correct |
60 |
Correct |
1689 ms |
440 KB |
Output is correct |
61 |
Correct |
1689 ms |
440 KB |
Output is correct |
62 |
Correct |
1687 ms |
440 KB |
Output is correct |
63 |
Correct |
1690 ms |
492 KB |
Output is correct |
64 |
Correct |
1784 ms |
492 KB |
Output is correct |
65 |
Correct |
1790 ms |
440 KB |
Output is correct |
66 |
Correct |
1774 ms |
492 KB |
Output is correct |
67 |
Correct |
1762 ms |
364 KB |
Output is correct |
68 |
Correct |
1811 ms |
492 KB |
Output is correct |
69 |
Correct |
1739 ms |
440 KB |
Output is correct |
70 |
Correct |
1763 ms |
440 KB |
Output is correct |
71 |
Correct |
1728 ms |
440 KB |
Output is correct |
72 |
Correct |
1739 ms |
492 KB |
Output is correct |
73 |
Correct |
1723 ms |
568 KB |
Output is correct |
74 |
Correct |
188 ms |
440 KB |
Output is correct |
75 |
Correct |
189 ms |
492 KB |
Output is correct |
76 |
Correct |
189 ms |
364 KB |
Output is correct |
77 |
Correct |
191 ms |
440 KB |
Output is correct |
78 |
Correct |
190 ms |
492 KB |
Output is correct |