# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
985068 |
2024-05-17T10:19:58 Z |
siewjh |
Boat (APIO16_boat) |
C++17 |
|
484 ms |
4556 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll pref[505][1005], ia[505];
ll pwr(ll a, ll b){
ll ans = 1;
while (b){
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
ll inv(ll a){
return pwr(a, mod - 2);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int nums; cin >> nums;
for (int i = 1; i <= nums; i++) ia[i] = inv(i);
vector<ll> av(nums + 1), bv(nums + 1), disc; disc.push_back(-1);
for (int i = 1; i <= nums; i++){
ll a, b; cin >> a >> b; b++;
av[i] = a; bv[i] = b;
disc.push_back(a); disc.push_back(b);
}
sort(disc.begin(), disc.end());
disc.resize(distance(disc.begin(), unique(disc.begin(), disc.end())));
int segs = disc.size() - 2;
for (int j = 0; j <= segs; j++) pref[0][j] = 1;
ll ans = 0;
for (int i = 1; i <= nums; i++)
for (int j = 1; j <= segs; j++){
ll dpv = 0, len = disc[j + 1] - disc[j];
if (av[i] <= disc[j] && bv[i] >= disc[j + 1]){
ll cv = len; int cnt = 1;
for (int k = i - 1; k >= 0; k--){
dpv = (dpv + pref[k][j - 1] * cv % mod) % mod;
if (av[k] <= disc[j] && bv[k] >= disc[j + 1]){
cnt++; cv = cv * (len + cnt - 1) % mod * ia[cnt] % mod;
}
}
}
pref[i][j] = (pref[i][j - 1] + dpv) % mod;
ans = (ans + dpv) % mod;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4184 KB |
Output is correct |
2 |
Correct |
4 ms |
4184 KB |
Output is correct |
3 |
Correct |
5 ms |
4284 KB |
Output is correct |
4 |
Correct |
5 ms |
4188 KB |
Output is correct |
5 |
Correct |
5 ms |
4444 KB |
Output is correct |
6 |
Correct |
4 ms |
4188 KB |
Output is correct |
7 |
Correct |
5 ms |
4444 KB |
Output is correct |
8 |
Correct |
4 ms |
4188 KB |
Output is correct |
9 |
Correct |
4 ms |
4188 KB |
Output is correct |
10 |
Correct |
4 ms |
4184 KB |
Output is correct |
11 |
Correct |
5 ms |
4188 KB |
Output is correct |
12 |
Correct |
4 ms |
4280 KB |
Output is correct |
13 |
Correct |
5 ms |
4188 KB |
Output is correct |
14 |
Correct |
4 ms |
4188 KB |
Output is correct |
15 |
Correct |
5 ms |
4312 KB |
Output is correct |
16 |
Correct |
3 ms |
3032 KB |
Output is correct |
17 |
Correct |
3 ms |
3160 KB |
Output is correct |
18 |
Correct |
3 ms |
3032 KB |
Output is correct |
19 |
Correct |
3 ms |
3160 KB |
Output is correct |
20 |
Correct |
3 ms |
3160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4184 KB |
Output is correct |
2 |
Correct |
4 ms |
4184 KB |
Output is correct |
3 |
Correct |
5 ms |
4284 KB |
Output is correct |
4 |
Correct |
5 ms |
4188 KB |
Output is correct |
5 |
Correct |
5 ms |
4444 KB |
Output is correct |
6 |
Correct |
4 ms |
4188 KB |
Output is correct |
7 |
Correct |
5 ms |
4444 KB |
Output is correct |
8 |
Correct |
4 ms |
4188 KB |
Output is correct |
9 |
Correct |
4 ms |
4188 KB |
Output is correct |
10 |
Correct |
4 ms |
4184 KB |
Output is correct |
11 |
Correct |
5 ms |
4188 KB |
Output is correct |
12 |
Correct |
4 ms |
4280 KB |
Output is correct |
13 |
Correct |
5 ms |
4188 KB |
Output is correct |
14 |
Correct |
4 ms |
4188 KB |
Output is correct |
15 |
Correct |
5 ms |
4312 KB |
Output is correct |
16 |
Correct |
3 ms |
3032 KB |
Output is correct |
17 |
Correct |
3 ms |
3160 KB |
Output is correct |
18 |
Correct |
3 ms |
3032 KB |
Output is correct |
19 |
Correct |
3 ms |
3160 KB |
Output is correct |
20 |
Correct |
3 ms |
3160 KB |
Output is correct |
21 |
Correct |
223 ms |
4332 KB |
Output is correct |
22 |
Correct |
218 ms |
4244 KB |
Output is correct |
23 |
Correct |
191 ms |
4252 KB |
Output is correct |
24 |
Correct |
209 ms |
4176 KB |
Output is correct |
25 |
Correct |
222 ms |
4556 KB |
Output is correct |
26 |
Correct |
416 ms |
4432 KB |
Output is correct |
27 |
Correct |
429 ms |
4176 KB |
Output is correct |
28 |
Correct |
420 ms |
4212 KB |
Output is correct |
29 |
Correct |
412 ms |
4176 KB |
Output is correct |
30 |
Correct |
5 ms |
4188 KB |
Output is correct |
31 |
Correct |
5 ms |
4184 KB |
Output is correct |
32 |
Correct |
6 ms |
4188 KB |
Output is correct |
33 |
Correct |
5 ms |
4188 KB |
Output is correct |
34 |
Correct |
5 ms |
4188 KB |
Output is correct |
35 |
Correct |
6 ms |
4188 KB |
Output is correct |
36 |
Correct |
6 ms |
4452 KB |
Output is correct |
37 |
Correct |
6 ms |
4308 KB |
Output is correct |
38 |
Correct |
6 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
860 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
3 ms |
860 KB |
Output is correct |
5 |
Correct |
3 ms |
860 KB |
Output is correct |
6 |
Correct |
4 ms |
860 KB |
Output is correct |
7 |
Correct |
4 ms |
860 KB |
Output is correct |
8 |
Correct |
4 ms |
860 KB |
Output is correct |
9 |
Correct |
4 ms |
860 KB |
Output is correct |
10 |
Correct |
5 ms |
860 KB |
Output is correct |
11 |
Correct |
3 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
860 KB |
Output is correct |
13 |
Correct |
3 ms |
860 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4184 KB |
Output is correct |
2 |
Correct |
4 ms |
4184 KB |
Output is correct |
3 |
Correct |
5 ms |
4284 KB |
Output is correct |
4 |
Correct |
5 ms |
4188 KB |
Output is correct |
5 |
Correct |
5 ms |
4444 KB |
Output is correct |
6 |
Correct |
4 ms |
4188 KB |
Output is correct |
7 |
Correct |
5 ms |
4444 KB |
Output is correct |
8 |
Correct |
4 ms |
4188 KB |
Output is correct |
9 |
Correct |
4 ms |
4188 KB |
Output is correct |
10 |
Correct |
4 ms |
4184 KB |
Output is correct |
11 |
Correct |
5 ms |
4188 KB |
Output is correct |
12 |
Correct |
4 ms |
4280 KB |
Output is correct |
13 |
Correct |
5 ms |
4188 KB |
Output is correct |
14 |
Correct |
4 ms |
4188 KB |
Output is correct |
15 |
Correct |
5 ms |
4312 KB |
Output is correct |
16 |
Correct |
3 ms |
3032 KB |
Output is correct |
17 |
Correct |
3 ms |
3160 KB |
Output is correct |
18 |
Correct |
3 ms |
3032 KB |
Output is correct |
19 |
Correct |
3 ms |
3160 KB |
Output is correct |
20 |
Correct |
3 ms |
3160 KB |
Output is correct |
21 |
Correct |
223 ms |
4332 KB |
Output is correct |
22 |
Correct |
218 ms |
4244 KB |
Output is correct |
23 |
Correct |
191 ms |
4252 KB |
Output is correct |
24 |
Correct |
209 ms |
4176 KB |
Output is correct |
25 |
Correct |
222 ms |
4556 KB |
Output is correct |
26 |
Correct |
416 ms |
4432 KB |
Output is correct |
27 |
Correct |
429 ms |
4176 KB |
Output is correct |
28 |
Correct |
420 ms |
4212 KB |
Output is correct |
29 |
Correct |
412 ms |
4176 KB |
Output is correct |
30 |
Correct |
5 ms |
4188 KB |
Output is correct |
31 |
Correct |
5 ms |
4184 KB |
Output is correct |
32 |
Correct |
6 ms |
4188 KB |
Output is correct |
33 |
Correct |
5 ms |
4188 KB |
Output is correct |
34 |
Correct |
5 ms |
4188 KB |
Output is correct |
35 |
Correct |
6 ms |
4188 KB |
Output is correct |
36 |
Correct |
6 ms |
4452 KB |
Output is correct |
37 |
Correct |
6 ms |
4308 KB |
Output is correct |
38 |
Correct |
6 ms |
4444 KB |
Output is correct |
39 |
Correct |
3 ms |
860 KB |
Output is correct |
40 |
Correct |
2 ms |
860 KB |
Output is correct |
41 |
Correct |
2 ms |
860 KB |
Output is correct |
42 |
Correct |
3 ms |
860 KB |
Output is correct |
43 |
Correct |
3 ms |
860 KB |
Output is correct |
44 |
Correct |
4 ms |
860 KB |
Output is correct |
45 |
Correct |
4 ms |
860 KB |
Output is correct |
46 |
Correct |
4 ms |
860 KB |
Output is correct |
47 |
Correct |
4 ms |
860 KB |
Output is correct |
48 |
Correct |
5 ms |
860 KB |
Output is correct |
49 |
Correct |
3 ms |
860 KB |
Output is correct |
50 |
Correct |
3 ms |
860 KB |
Output is correct |
51 |
Correct |
3 ms |
860 KB |
Output is correct |
52 |
Correct |
2 ms |
860 KB |
Output is correct |
53 |
Correct |
3 ms |
860 KB |
Output is correct |
54 |
Correct |
2 ms |
860 KB |
Output is correct |
55 |
Correct |
2 ms |
860 KB |
Output is correct |
56 |
Correct |
2 ms |
860 KB |
Output is correct |
57 |
Correct |
2 ms |
856 KB |
Output is correct |
58 |
Correct |
2 ms |
860 KB |
Output is correct |
59 |
Correct |
252 ms |
4464 KB |
Output is correct |
60 |
Correct |
229 ms |
4252 KB |
Output is correct |
61 |
Correct |
209 ms |
4332 KB |
Output is correct |
62 |
Correct |
246 ms |
4276 KB |
Output is correct |
63 |
Correct |
231 ms |
4180 KB |
Output is correct |
64 |
Correct |
474 ms |
4520 KB |
Output is correct |
65 |
Correct |
476 ms |
4280 KB |
Output is correct |
66 |
Correct |
475 ms |
4400 KB |
Output is correct |
67 |
Correct |
483 ms |
4288 KB |
Output is correct |
68 |
Correct |
484 ms |
4280 KB |
Output is correct |
69 |
Correct |
195 ms |
4236 KB |
Output is correct |
70 |
Correct |
193 ms |
4304 KB |
Output is correct |
71 |
Correct |
189 ms |
4180 KB |
Output is correct |
72 |
Correct |
201 ms |
4236 KB |
Output is correct |
73 |
Correct |
202 ms |
4236 KB |
Output is correct |
74 |
Correct |
50 ms |
3112 KB |
Output is correct |
75 |
Correct |
47 ms |
3156 KB |
Output is correct |
76 |
Correct |
51 ms |
3156 KB |
Output is correct |
77 |
Correct |
51 ms |
3024 KB |
Output is correct |
78 |
Correct |
53 ms |
3088 KB |
Output is correct |