# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
523175 |
2022-02-07T07:17:34 Z |
blue |
Boat (APIO16_boat) |
C++17 |
|
1979 ms |
12268 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define sz(x) int(x.size())
const ll mod = 1'000'000'007;
ll mul(ll a, ll b)
{
return (a*b) % mod;
}
ll ad(ll a, ll b)
{
return (a+b) % mod;
}
ll sq(ll a)
{
return mul(a,a);
}
ll pow(ll b, ll e)
{
if(e == 0) return 1;
else if(e % 2 == 1) return mul(b, pow(b, e-1));
else return sq(pow(b, e/2));
}
ll get_inv(ll a)
{
return pow(a, mod-2);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
ll a[1+N], b[1+N];
map<ll, ll> values;
for(int i = 1; i <= N; i++)
{
cin >> a[i] >> b[i];
b[i]++;
values[a[i]] = 0;
values[b[i]] = 0;
}
values[0] = 0;
values[1] = 0;
vll ep;
for(auto& z : values) ep.push_back(z.first);
int ct = sz(ep) - 1;
vll blocksize(1+ct);
blocksize[0] = 0;
for(int i = 1; i <= ct; i++)
blocksize[i] = ep[i] - ep[i-1];
int x[1+N], y[1+N];
// for(int i = 0; i <= ct; i++) cerr << i << " : " << ep[i] << ' ' << blocksize[i] << '\n';
for(int i = 1; i <= N; i++)
{
x[i] = 0;
int lo = 1, hi = ct;
while(lo != hi)
{
int mid = (lo+hi)/2 + 1;
if(ep[mid] <= a[i])
lo = mid;
else
hi = mid-1;
}
x[i] = lo + 1;
y[i] = 0;
lo = 1, hi = ct;
while(lo != hi)
{
int mid = (lo+hi)/2+1;
if(ep[mid] <= b[i])
lo = mid;
else
hi = mid-1;
}
y[i] = lo;
}
ll*** DP = new ll**[1+N];
for(int i = 0; i <= N; i++)
{
if(i <= 1)
{
DP[i] = new ll*[1+ct];
for(int j = 0; j <= ct; j++)
{
DP[i][j] = new ll[1+N];
for(int k = 0; k <= N; k++) DP[i][j][k] = 0;
}
}
else DP[i] = DP[i-2];
}
ll inv[1+N];
for(int i = 1; i <= N; i++) inv[i] = get_inv(i);
vvll DPsum(1+N, vll(1+ct, 0));
// cerr << "!" << x[1] << ' ' << y[1] << '\n';
for(int j = x[1]; j <= y[1]; j++)
{
DPsum[1][j] = ad(DPsum[1][j], blocksize[j]);
DP[1][j][1] = blocksize[j];
}
for(int i = 2; i <= N; i++)
{
for(int j = 0; j <= ct; j++)
for(int k = 0; k <= N; k++)
DP[i][j][k] = 0;
for(int j = 1; j <= ct; j++)
{
for(int k = 1; k <= i; k++)
{
DP[i][j][k] = DP[i-1][j][k];
if(x[i] <= j && j <= y[i])
{
if(j == 1 && k == 1)
{
;//DP[i][1][1] = blocksize[j] *
}
else if(j == 1)
{
;
}
else if(k == 1)
{
ll curr = 1;
for(int j2 = 1; j2 < j; j2++)
curr = ad(curr, DPsum[i-1][j2]);
DP[i][j][1] = ad(DP[i][j][1], mul(curr, blocksize[j]));
}
else
{
if(k <= blocksize[j])
DP[i][j][k] = ad(DP[i][j][k], mul(DP[i-1][j][k-1], mul(blocksize[j] - k + 1, inv[k])));
}
}
DPsum[i][j] = ad(DPsum[i][j], DP[i][j][k]);
}
}
}
ll res = 0;
for(int j = 1; j <= ct; j++)
res = ad(res, DPsum[N][j]);
cout << res << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
990 ms |
12268 KB |
Output is correct |
2 |
Correct |
988 ms |
12256 KB |
Output is correct |
3 |
Correct |
993 ms |
12252 KB |
Output is correct |
4 |
Correct |
991 ms |
12248 KB |
Output is correct |
5 |
Correct |
971 ms |
12236 KB |
Output is correct |
6 |
Correct |
1020 ms |
12248 KB |
Output is correct |
7 |
Correct |
961 ms |
12252 KB |
Output is correct |
8 |
Correct |
991 ms |
12248 KB |
Output is correct |
9 |
Correct |
1006 ms |
12248 KB |
Output is correct |
10 |
Correct |
1014 ms |
12256 KB |
Output is correct |
11 |
Correct |
1010 ms |
12252 KB |
Output is correct |
12 |
Correct |
992 ms |
12252 KB |
Output is correct |
13 |
Correct |
964 ms |
12244 KB |
Output is correct |
14 |
Correct |
995 ms |
12248 KB |
Output is correct |
15 |
Correct |
992 ms |
12256 KB |
Output is correct |
16 |
Correct |
164 ms |
2380 KB |
Output is correct |
17 |
Correct |
162 ms |
2520 KB |
Output is correct |
18 |
Correct |
164 ms |
2524 KB |
Output is correct |
19 |
Correct |
194 ms |
2636 KB |
Output is correct |
20 |
Correct |
156 ms |
2552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
990 ms |
12268 KB |
Output is correct |
2 |
Correct |
988 ms |
12256 KB |
Output is correct |
3 |
Correct |
993 ms |
12252 KB |
Output is correct |
4 |
Correct |
991 ms |
12248 KB |
Output is correct |
5 |
Correct |
971 ms |
12236 KB |
Output is correct |
6 |
Correct |
1020 ms |
12248 KB |
Output is correct |
7 |
Correct |
961 ms |
12252 KB |
Output is correct |
8 |
Correct |
991 ms |
12248 KB |
Output is correct |
9 |
Correct |
1006 ms |
12248 KB |
Output is correct |
10 |
Correct |
1014 ms |
12256 KB |
Output is correct |
11 |
Correct |
1010 ms |
12252 KB |
Output is correct |
12 |
Correct |
992 ms |
12252 KB |
Output is correct |
13 |
Correct |
964 ms |
12244 KB |
Output is correct |
14 |
Correct |
995 ms |
12248 KB |
Output is correct |
15 |
Correct |
992 ms |
12256 KB |
Output is correct |
16 |
Correct |
164 ms |
2380 KB |
Output is correct |
17 |
Correct |
162 ms |
2520 KB |
Output is correct |
18 |
Correct |
164 ms |
2524 KB |
Output is correct |
19 |
Correct |
194 ms |
2636 KB |
Output is correct |
20 |
Correct |
156 ms |
2552 KB |
Output is correct |
21 |
Correct |
1209 ms |
11200 KB |
Output is correct |
22 |
Correct |
1180 ms |
11340 KB |
Output is correct |
23 |
Correct |
1178 ms |
11136 KB |
Output is correct |
24 |
Correct |
1186 ms |
11060 KB |
Output is correct |
25 |
Correct |
1180 ms |
11108 KB |
Output is correct |
26 |
Correct |
1286 ms |
10820 KB |
Output is correct |
27 |
Correct |
1320 ms |
10984 KB |
Output is correct |
28 |
Correct |
1268 ms |
10792 KB |
Output is correct |
29 |
Correct |
1293 ms |
10744 KB |
Output is correct |
30 |
Correct |
985 ms |
12212 KB |
Output is correct |
31 |
Correct |
999 ms |
12236 KB |
Output is correct |
32 |
Correct |
987 ms |
12208 KB |
Output is correct |
33 |
Correct |
991 ms |
12236 KB |
Output is correct |
34 |
Correct |
1070 ms |
12200 KB |
Output is correct |
35 |
Correct |
1051 ms |
12212 KB |
Output is correct |
36 |
Correct |
1071 ms |
12216 KB |
Output is correct |
37 |
Correct |
1016 ms |
12220 KB |
Output is correct |
38 |
Correct |
984 ms |
12192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
716 KB |
Output is correct |
2 |
Correct |
13 ms |
816 KB |
Output is correct |
3 |
Correct |
13 ms |
716 KB |
Output is correct |
4 |
Correct |
15 ms |
784 KB |
Output is correct |
5 |
Correct |
13 ms |
716 KB |
Output is correct |
6 |
Correct |
17 ms |
716 KB |
Output is correct |
7 |
Correct |
14 ms |
776 KB |
Output is correct |
8 |
Correct |
14 ms |
788 KB |
Output is correct |
9 |
Correct |
13 ms |
780 KB |
Output is correct |
10 |
Correct |
15 ms |
780 KB |
Output is correct |
11 |
Correct |
12 ms |
776 KB |
Output is correct |
12 |
Correct |
12 ms |
776 KB |
Output is correct |
13 |
Correct |
15 ms |
784 KB |
Output is correct |
14 |
Correct |
14 ms |
716 KB |
Output is correct |
15 |
Correct |
13 ms |
716 KB |
Output is correct |
16 |
Correct |
7 ms |
608 KB |
Output is correct |
17 |
Correct |
7 ms |
608 KB |
Output is correct |
18 |
Correct |
6 ms |
588 KB |
Output is correct |
19 |
Correct |
6 ms |
596 KB |
Output is correct |
20 |
Correct |
6 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
990 ms |
12268 KB |
Output is correct |
2 |
Correct |
988 ms |
12256 KB |
Output is correct |
3 |
Correct |
993 ms |
12252 KB |
Output is correct |
4 |
Correct |
991 ms |
12248 KB |
Output is correct |
5 |
Correct |
971 ms |
12236 KB |
Output is correct |
6 |
Correct |
1020 ms |
12248 KB |
Output is correct |
7 |
Correct |
961 ms |
12252 KB |
Output is correct |
8 |
Correct |
991 ms |
12248 KB |
Output is correct |
9 |
Correct |
1006 ms |
12248 KB |
Output is correct |
10 |
Correct |
1014 ms |
12256 KB |
Output is correct |
11 |
Correct |
1010 ms |
12252 KB |
Output is correct |
12 |
Correct |
992 ms |
12252 KB |
Output is correct |
13 |
Correct |
964 ms |
12244 KB |
Output is correct |
14 |
Correct |
995 ms |
12248 KB |
Output is correct |
15 |
Correct |
992 ms |
12256 KB |
Output is correct |
16 |
Correct |
164 ms |
2380 KB |
Output is correct |
17 |
Correct |
162 ms |
2520 KB |
Output is correct |
18 |
Correct |
164 ms |
2524 KB |
Output is correct |
19 |
Correct |
194 ms |
2636 KB |
Output is correct |
20 |
Correct |
156 ms |
2552 KB |
Output is correct |
21 |
Correct |
1209 ms |
11200 KB |
Output is correct |
22 |
Correct |
1180 ms |
11340 KB |
Output is correct |
23 |
Correct |
1178 ms |
11136 KB |
Output is correct |
24 |
Correct |
1186 ms |
11060 KB |
Output is correct |
25 |
Correct |
1180 ms |
11108 KB |
Output is correct |
26 |
Correct |
1286 ms |
10820 KB |
Output is correct |
27 |
Correct |
1320 ms |
10984 KB |
Output is correct |
28 |
Correct |
1268 ms |
10792 KB |
Output is correct |
29 |
Correct |
1293 ms |
10744 KB |
Output is correct |
30 |
Correct |
985 ms |
12212 KB |
Output is correct |
31 |
Correct |
999 ms |
12236 KB |
Output is correct |
32 |
Correct |
987 ms |
12208 KB |
Output is correct |
33 |
Correct |
991 ms |
12236 KB |
Output is correct |
34 |
Correct |
1070 ms |
12200 KB |
Output is correct |
35 |
Correct |
1051 ms |
12212 KB |
Output is correct |
36 |
Correct |
1071 ms |
12216 KB |
Output is correct |
37 |
Correct |
1016 ms |
12220 KB |
Output is correct |
38 |
Correct |
984 ms |
12192 KB |
Output is correct |
39 |
Correct |
12 ms |
716 KB |
Output is correct |
40 |
Correct |
13 ms |
816 KB |
Output is correct |
41 |
Correct |
13 ms |
716 KB |
Output is correct |
42 |
Correct |
15 ms |
784 KB |
Output is correct |
43 |
Correct |
13 ms |
716 KB |
Output is correct |
44 |
Correct |
17 ms |
716 KB |
Output is correct |
45 |
Correct |
14 ms |
776 KB |
Output is correct |
46 |
Correct |
14 ms |
788 KB |
Output is correct |
47 |
Correct |
13 ms |
780 KB |
Output is correct |
48 |
Correct |
15 ms |
780 KB |
Output is correct |
49 |
Correct |
12 ms |
776 KB |
Output is correct |
50 |
Correct |
12 ms |
776 KB |
Output is correct |
51 |
Correct |
15 ms |
784 KB |
Output is correct |
52 |
Correct |
14 ms |
716 KB |
Output is correct |
53 |
Correct |
13 ms |
716 KB |
Output is correct |
54 |
Correct |
7 ms |
608 KB |
Output is correct |
55 |
Correct |
7 ms |
608 KB |
Output is correct |
56 |
Correct |
6 ms |
588 KB |
Output is correct |
57 |
Correct |
6 ms |
596 KB |
Output is correct |
58 |
Correct |
6 ms |
600 KB |
Output is correct |
59 |
Correct |
1628 ms |
12248 KB |
Output is correct |
60 |
Correct |
1546 ms |
12256 KB |
Output is correct |
61 |
Correct |
1605 ms |
12252 KB |
Output is correct |
62 |
Correct |
1670 ms |
12256 KB |
Output is correct |
63 |
Correct |
1700 ms |
12260 KB |
Output is correct |
64 |
Correct |
1934 ms |
12256 KB |
Output is correct |
65 |
Correct |
1910 ms |
12252 KB |
Output is correct |
66 |
Correct |
1979 ms |
12252 KB |
Output is correct |
67 |
Correct |
1912 ms |
12252 KB |
Output is correct |
68 |
Correct |
1945 ms |
12252 KB |
Output is correct |
69 |
Correct |
1549 ms |
12252 KB |
Output is correct |
70 |
Correct |
1481 ms |
12252 KB |
Output is correct |
71 |
Correct |
1447 ms |
12256 KB |
Output is correct |
72 |
Correct |
1519 ms |
12252 KB |
Output is correct |
73 |
Correct |
1464 ms |
12252 KB |
Output is correct |
74 |
Correct |
202 ms |
2508 KB |
Output is correct |
75 |
Correct |
199 ms |
2508 KB |
Output is correct |
76 |
Correct |
194 ms |
2548 KB |
Output is correct |
77 |
Correct |
208 ms |
2536 KB |
Output is correct |
78 |
Correct |
190 ms |
2508 KB |
Output is correct |