# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
557726 |
2022-05-06T01:03:18 Z |
hhhhaura |
Boat (APIO16_boat) |
C++14 |
|
1696 ms |
18252 KB |
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i --)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)
using namespace std;
#ifdef wiwihorz
#define print(a...)cerr<<"Line "<<__LINE__<<":",kout("["+string(#a)+"] = ", a)
void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
void kout() { cerr << endl; }
template<class T1,class ... T2>void kout(T1 a,T2 ... e){cerr<<a<<" ",kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
#define x first
#define y second
namespace solver {
int n, tot;
vector<pii> seg;
vector<int> v, fac, inv;
vector<vector<int>> dp, pre, P, cal, C;
int pow_(int a, int times) {
int ans = 1;
for(; times > 0; times >>= 1, a = a * a % MOD) {
if(times & 1) ans = ans * a % MOD;
}
return ans;
}
void init_(int _n) {
n = _n;
v.clear();
seg.assign(n + 1, {0, 0});
dp.assign(n + 1, vector<int>(n * 2 + 1, 0));
pre.assign(n * 2 + 1, vector<int>(n + 1, 0));
P.assign(n * 2 + 1, vector<int>(n + 1, 0));
C.assign(n + 1, vector<int>(n + 1, 0));
cal.assign(n * 2 + 1, vector<int>(n + 1, 0));
fac.assign(n + 1, 1);
inv.assign(n + 1, 1);
rep(i, 1, n) fac[i] = fac[i - 1] * i % MOD;
inv[n] = pow_(fac[n], MOD - 2);
rrep(i, 1, n - 1) inv[i] = inv[i + 1] * (i + 1) % MOD;
rep(i, 0, n) rep(j, 0, i) {
C[i][j] = fac[i] * inv[j] % MOD * inv[i - j] % MOD;
}
}
void solve() {
sort(all(v));
v.resize(unique(all(v)) - v.begin());
tot = v.size() - 1;
rep(i, 1, n) {
int L = seg[i].x, R = seg[i].y;
L = lower_bound(all(v), L) - v.begin() + 1;
R = lower_bound(all(v), R + 1) - v.begin();
seg[i] = {L, R};
}
int l = 0, cur = 1;
rep(i, 1, tot) {
int len = v[i] - v[i - 1];
rep(j, 1, min(n, len)) {
int L = 1, R = 1;
rep(k, 0, j - 1) L = L * (len - k) % MOD;
rep(k, 1, j) R = R * k % MOD;
P[i][j] = L * pow_(R, MOD - 2) % MOD;
}
}
rep(i, 1, tot) {
vector<int> p = P[i];
rep(j, 1, n) {
rep(k, 1, j) cal[i][j] += p[k] * C[j - 1][k - 1] % MOD;
cal[i][j] %= MOD;
}
}
dp[0][0] = 1;
rep(i, 0, tot) pre[i][0] = 1;
rep(i, 1, n) {
int L = seg[i].x, R = seg[i].y;
rep(j, 1, tot) if(L <= j && j <= R) {
int cnt = 0;
rrep(k, 0, i - 1) {
cnt += (seg[k + 1].x <= j && seg[k + 1].y >= j);
dp[i][j] += pre[j - 1][k] * cal[j][cnt] % MOD;
}
dp[i][j] %= MOD;
}
rep(j, 1, tot) pre[j][i] = (pre[j - 1][i] + dp[i][j]) % MOD;
}
int ans = 0;
rep(i, 1, n) ans = (ans + pre[tot][i]) % MOD;
cout << ans << "\n";
}
};
using namespace solver;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int n; cin >> n;
init_(n);
rep(i, 1, n) {
cin >> seg[i].x >> seg[i].y;
v.push_back(seg[i].x);
v.push_back(seg[i].y + 1);
}
solve();
return 0;
}
Compilation message
boat.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
5 | #pragma loop-opt(on)
|
boat.cpp:20:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
20 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
| ^~~~
boat.cpp:20:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
20 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
| ^~~~
boat.cpp: In function 'void solver::solve()':
boat.cpp:70:7: warning: unused variable 'l' [-Wunused-variable]
70 | int l = 0, cur = 1;
| ^
boat.cpp:70:14: warning: unused variable 'cur' [-Wunused-variable]
70 | int l = 0, cur = 1;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
851 ms |
18132 KB |
Output is correct |
2 |
Correct |
901 ms |
18132 KB |
Output is correct |
3 |
Correct |
868 ms |
18132 KB |
Output is correct |
4 |
Correct |
877 ms |
18132 KB |
Output is correct |
5 |
Correct |
903 ms |
18132 KB |
Output is correct |
6 |
Correct |
869 ms |
18132 KB |
Output is correct |
7 |
Correct |
888 ms |
18132 KB |
Output is correct |
8 |
Correct |
883 ms |
18132 KB |
Output is correct |
9 |
Correct |
875 ms |
18132 KB |
Output is correct |
10 |
Correct |
863 ms |
18132 KB |
Output is correct |
11 |
Correct |
862 ms |
18132 KB |
Output is correct |
12 |
Correct |
876 ms |
18132 KB |
Output is correct |
13 |
Correct |
865 ms |
18120 KB |
Output is correct |
14 |
Correct |
896 ms |
18132 KB |
Output is correct |
15 |
Correct |
879 ms |
18132 KB |
Output is correct |
16 |
Correct |
156 ms |
18132 KB |
Output is correct |
17 |
Correct |
183 ms |
18124 KB |
Output is correct |
18 |
Correct |
164 ms |
18132 KB |
Output is correct |
19 |
Correct |
165 ms |
18040 KB |
Output is correct |
20 |
Correct |
175 ms |
18132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
851 ms |
18132 KB |
Output is correct |
2 |
Correct |
901 ms |
18132 KB |
Output is correct |
3 |
Correct |
868 ms |
18132 KB |
Output is correct |
4 |
Correct |
877 ms |
18132 KB |
Output is correct |
5 |
Correct |
903 ms |
18132 KB |
Output is correct |
6 |
Correct |
869 ms |
18132 KB |
Output is correct |
7 |
Correct |
888 ms |
18132 KB |
Output is correct |
8 |
Correct |
883 ms |
18132 KB |
Output is correct |
9 |
Correct |
875 ms |
18132 KB |
Output is correct |
10 |
Correct |
863 ms |
18132 KB |
Output is correct |
11 |
Correct |
862 ms |
18132 KB |
Output is correct |
12 |
Correct |
876 ms |
18132 KB |
Output is correct |
13 |
Correct |
865 ms |
18120 KB |
Output is correct |
14 |
Correct |
896 ms |
18132 KB |
Output is correct |
15 |
Correct |
879 ms |
18132 KB |
Output is correct |
16 |
Correct |
156 ms |
18132 KB |
Output is correct |
17 |
Correct |
183 ms |
18124 KB |
Output is correct |
18 |
Correct |
164 ms |
18132 KB |
Output is correct |
19 |
Correct |
165 ms |
18040 KB |
Output is correct |
20 |
Correct |
175 ms |
18132 KB |
Output is correct |
21 |
Correct |
330 ms |
18132 KB |
Output is correct |
22 |
Correct |
364 ms |
18132 KB |
Output is correct |
23 |
Correct |
302 ms |
18132 KB |
Output is correct |
24 |
Correct |
343 ms |
18252 KB |
Output is correct |
25 |
Correct |
339 ms |
18132 KB |
Output is correct |
26 |
Correct |
383 ms |
18132 KB |
Output is correct |
27 |
Correct |
376 ms |
18132 KB |
Output is correct |
28 |
Correct |
379 ms |
18132 KB |
Output is correct |
29 |
Correct |
358 ms |
18132 KB |
Output is correct |
30 |
Correct |
794 ms |
18132 KB |
Output is correct |
31 |
Correct |
818 ms |
18132 KB |
Output is correct |
32 |
Correct |
808 ms |
18132 KB |
Output is correct |
33 |
Correct |
787 ms |
18140 KB |
Output is correct |
34 |
Correct |
801 ms |
18132 KB |
Output is correct |
35 |
Correct |
798 ms |
18132 KB |
Output is correct |
36 |
Correct |
831 ms |
18140 KB |
Output is correct |
37 |
Correct |
872 ms |
18132 KB |
Output is correct |
38 |
Correct |
824 ms |
18132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
980 KB |
Output is correct |
2 |
Correct |
16 ms |
1068 KB |
Output is correct |
3 |
Correct |
15 ms |
1068 KB |
Output is correct |
4 |
Correct |
15 ms |
1064 KB |
Output is correct |
5 |
Correct |
16 ms |
980 KB |
Output is correct |
6 |
Correct |
16 ms |
980 KB |
Output is correct |
7 |
Correct |
17 ms |
1068 KB |
Output is correct |
8 |
Correct |
16 ms |
992 KB |
Output is correct |
9 |
Correct |
17 ms |
1068 KB |
Output is correct |
10 |
Correct |
18 ms |
1064 KB |
Output is correct |
11 |
Correct |
16 ms |
980 KB |
Output is correct |
12 |
Correct |
15 ms |
1068 KB |
Output is correct |
13 |
Correct |
18 ms |
980 KB |
Output is correct |
14 |
Correct |
18 ms |
1064 KB |
Output is correct |
15 |
Correct |
18 ms |
1068 KB |
Output is correct |
16 |
Correct |
8 ms |
980 KB |
Output is correct |
17 |
Correct |
8 ms |
1064 KB |
Output is correct |
18 |
Correct |
7 ms |
980 KB |
Output is correct |
19 |
Correct |
8 ms |
1060 KB |
Output is correct |
20 |
Correct |
8 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
851 ms |
18132 KB |
Output is correct |
2 |
Correct |
901 ms |
18132 KB |
Output is correct |
3 |
Correct |
868 ms |
18132 KB |
Output is correct |
4 |
Correct |
877 ms |
18132 KB |
Output is correct |
5 |
Correct |
903 ms |
18132 KB |
Output is correct |
6 |
Correct |
869 ms |
18132 KB |
Output is correct |
7 |
Correct |
888 ms |
18132 KB |
Output is correct |
8 |
Correct |
883 ms |
18132 KB |
Output is correct |
9 |
Correct |
875 ms |
18132 KB |
Output is correct |
10 |
Correct |
863 ms |
18132 KB |
Output is correct |
11 |
Correct |
862 ms |
18132 KB |
Output is correct |
12 |
Correct |
876 ms |
18132 KB |
Output is correct |
13 |
Correct |
865 ms |
18120 KB |
Output is correct |
14 |
Correct |
896 ms |
18132 KB |
Output is correct |
15 |
Correct |
879 ms |
18132 KB |
Output is correct |
16 |
Correct |
156 ms |
18132 KB |
Output is correct |
17 |
Correct |
183 ms |
18124 KB |
Output is correct |
18 |
Correct |
164 ms |
18132 KB |
Output is correct |
19 |
Correct |
165 ms |
18040 KB |
Output is correct |
20 |
Correct |
175 ms |
18132 KB |
Output is correct |
21 |
Correct |
330 ms |
18132 KB |
Output is correct |
22 |
Correct |
364 ms |
18132 KB |
Output is correct |
23 |
Correct |
302 ms |
18132 KB |
Output is correct |
24 |
Correct |
343 ms |
18252 KB |
Output is correct |
25 |
Correct |
339 ms |
18132 KB |
Output is correct |
26 |
Correct |
383 ms |
18132 KB |
Output is correct |
27 |
Correct |
376 ms |
18132 KB |
Output is correct |
28 |
Correct |
379 ms |
18132 KB |
Output is correct |
29 |
Correct |
358 ms |
18132 KB |
Output is correct |
30 |
Correct |
794 ms |
18132 KB |
Output is correct |
31 |
Correct |
818 ms |
18132 KB |
Output is correct |
32 |
Correct |
808 ms |
18132 KB |
Output is correct |
33 |
Correct |
787 ms |
18140 KB |
Output is correct |
34 |
Correct |
801 ms |
18132 KB |
Output is correct |
35 |
Correct |
798 ms |
18132 KB |
Output is correct |
36 |
Correct |
831 ms |
18140 KB |
Output is correct |
37 |
Correct |
872 ms |
18132 KB |
Output is correct |
38 |
Correct |
824 ms |
18132 KB |
Output is correct |
39 |
Correct |
16 ms |
980 KB |
Output is correct |
40 |
Correct |
16 ms |
1068 KB |
Output is correct |
41 |
Correct |
15 ms |
1068 KB |
Output is correct |
42 |
Correct |
15 ms |
1064 KB |
Output is correct |
43 |
Correct |
16 ms |
980 KB |
Output is correct |
44 |
Correct |
16 ms |
980 KB |
Output is correct |
45 |
Correct |
17 ms |
1068 KB |
Output is correct |
46 |
Correct |
16 ms |
992 KB |
Output is correct |
47 |
Correct |
17 ms |
1068 KB |
Output is correct |
48 |
Correct |
18 ms |
1064 KB |
Output is correct |
49 |
Correct |
16 ms |
980 KB |
Output is correct |
50 |
Correct |
15 ms |
1068 KB |
Output is correct |
51 |
Correct |
18 ms |
980 KB |
Output is correct |
52 |
Correct |
18 ms |
1064 KB |
Output is correct |
53 |
Correct |
18 ms |
1068 KB |
Output is correct |
54 |
Correct |
8 ms |
980 KB |
Output is correct |
55 |
Correct |
8 ms |
1064 KB |
Output is correct |
56 |
Correct |
7 ms |
980 KB |
Output is correct |
57 |
Correct |
8 ms |
1060 KB |
Output is correct |
58 |
Correct |
8 ms |
980 KB |
Output is correct |
59 |
Correct |
1632 ms |
18132 KB |
Output is correct |
60 |
Correct |
1633 ms |
18140 KB |
Output is correct |
61 |
Correct |
1621 ms |
18132 KB |
Output is correct |
62 |
Correct |
1637 ms |
18132 KB |
Output is correct |
63 |
Correct |
1640 ms |
18132 KB |
Output is correct |
64 |
Correct |
1689 ms |
18132 KB |
Output is correct |
65 |
Correct |
1696 ms |
18140 KB |
Output is correct |
66 |
Correct |
1679 ms |
18144 KB |
Output is correct |
67 |
Correct |
1671 ms |
18136 KB |
Output is correct |
68 |
Correct |
1677 ms |
18144 KB |
Output is correct |
69 |
Correct |
1594 ms |
18136 KB |
Output is correct |
70 |
Correct |
1590 ms |
18140 KB |
Output is correct |
71 |
Correct |
1601 ms |
18136 KB |
Output is correct |
72 |
Correct |
1594 ms |
18136 KB |
Output is correct |
73 |
Correct |
1606 ms |
18132 KB |
Output is correct |
74 |
Correct |
196 ms |
18252 KB |
Output is correct |
75 |
Correct |
213 ms |
18144 KB |
Output is correct |
76 |
Correct |
196 ms |
18252 KB |
Output is correct |
77 |
Correct |
215 ms |
18136 KB |
Output is correct |
78 |
Correct |
199 ms |
18148 KB |
Output is correct |