# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1106736 |
2024-10-31T02:15:43 Z |
12345678 |
Boat (APIO16_boat) |
C++17 |
|
765 ms |
18368 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=505, mod=1e9+7;
ll n, a[nx], b[nx], dp[nx][2*nx], qs[nx][2*nx], sz[2*nx], t, pv, ncr[nx][nx], choose[2*nx][nx], l[nx], r[nx], sm[2*nx][nx];
map<ll, ll> mp;
ll invmod(ll a, ll x)
{
if (x==0) return 1;
auto tmp=invmod(a, x/2);
tmp=(tmp*tmp)%mod;
if (x%2) return (tmp*a)%mod;
else return tmp;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>a[i]>>b[i], mp[--a[i]]=0, mp[b[i]]=0;
for (auto &[x, y]:mp) y=t, sz[t]=x-pv, pv=x, t++;
for (int i=1; i<=n; i++) l[i]=mp[a[i]], r[i]=mp[b[i]];
ncr[0][0]=1;
for (int i=1; i<=n; i++)
{
for (int j=0; j<=i; j++)
{
ncr[i][j]=ncr[i-1][j];
if (j>0) ncr[i][j]=(ncr[i][j]+ncr[i-1][j-1])%mod;
}
}
for (int i=1; i<t; i++)
{
ll tmp=1;
choose[i][0]=tmp;
for (int j=1; j<=min(sz[i], n); j++) tmp=(((tmp*(sz[i]-j+1))%mod)*invmod(j, mod-2))%mod, choose[i][j]=tmp;
}
for (int i=1; i<t; i++) for (int j=2; j<=n; j++) for (int x=0; x<=j-2; x++) sm[i][j]=(sm[i][j]+choose[i][x+2]*ncr[j-2][x])%mod;
for (int i=1; i<=n; i++)
{
for (int j=1; j<t; j++)
{
if (l[i]<j&&j<=r[i])
{
dp[i][j]=((qs[i-1][j-1]+1)*sz[j])%mod;
ll cnt=1;
for (int k=i-1; k>=1; k--)
{
if (l[k]<j&&j<=r[k])
{
cnt++;
if (cnt>=2) dp[i][j]=(dp[i][j]+sm[j][cnt]*(qs[k-1][j-1]+1))%mod;
}
}
}
//cout<<"dp "<<i<<' '<<j<<' '<<dp[i][j]<<'\n';
qs[i][j]=((dp[i][j]+qs[i-1][j]+qs[i][j-1]-qs[i-1][j-1])%mod+mod)%mod;
}
}
cout<<qs[n][t-1];
}
/*
2
1 3
1 3
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
545 ms |
16396 KB |
Output is correct |
2 |
Correct |
545 ms |
16392 KB |
Output is correct |
3 |
Correct |
550 ms |
16204 KB |
Output is correct |
4 |
Correct |
551 ms |
16200 KB |
Output is correct |
5 |
Correct |
549 ms |
16196 KB |
Output is correct |
6 |
Correct |
538 ms |
16536 KB |
Output is correct |
7 |
Correct |
536 ms |
16712 KB |
Output is correct |
8 |
Correct |
535 ms |
16712 KB |
Output is correct |
9 |
Correct |
536 ms |
16596 KB |
Output is correct |
10 |
Correct |
537 ms |
16660 KB |
Output is correct |
11 |
Correct |
538 ms |
16712 KB |
Output is correct |
12 |
Correct |
540 ms |
16712 KB |
Output is correct |
13 |
Correct |
536 ms |
16712 KB |
Output is correct |
14 |
Correct |
538 ms |
16712 KB |
Output is correct |
15 |
Correct |
536 ms |
16712 KB |
Output is correct |
16 |
Correct |
99 ms |
13384 KB |
Output is correct |
17 |
Correct |
107 ms |
13508 KB |
Output is correct |
18 |
Correct |
102 ms |
13648 KB |
Output is correct |
19 |
Correct |
108 ms |
13576 KB |
Output is correct |
20 |
Correct |
107 ms |
13640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
545 ms |
16396 KB |
Output is correct |
2 |
Correct |
545 ms |
16392 KB |
Output is correct |
3 |
Correct |
550 ms |
16204 KB |
Output is correct |
4 |
Correct |
551 ms |
16200 KB |
Output is correct |
5 |
Correct |
549 ms |
16196 KB |
Output is correct |
6 |
Correct |
538 ms |
16536 KB |
Output is correct |
7 |
Correct |
536 ms |
16712 KB |
Output is correct |
8 |
Correct |
535 ms |
16712 KB |
Output is correct |
9 |
Correct |
536 ms |
16596 KB |
Output is correct |
10 |
Correct |
537 ms |
16660 KB |
Output is correct |
11 |
Correct |
538 ms |
16712 KB |
Output is correct |
12 |
Correct |
540 ms |
16712 KB |
Output is correct |
13 |
Correct |
536 ms |
16712 KB |
Output is correct |
14 |
Correct |
538 ms |
16712 KB |
Output is correct |
15 |
Correct |
536 ms |
16712 KB |
Output is correct |
16 |
Correct |
99 ms |
13384 KB |
Output is correct |
17 |
Correct |
107 ms |
13508 KB |
Output is correct |
18 |
Correct |
102 ms |
13648 KB |
Output is correct |
19 |
Correct |
108 ms |
13576 KB |
Output is correct |
20 |
Correct |
107 ms |
13640 KB |
Output is correct |
21 |
Correct |
537 ms |
17416 KB |
Output is correct |
22 |
Correct |
531 ms |
17364 KB |
Output is correct |
23 |
Correct |
515 ms |
17224 KB |
Output is correct |
24 |
Correct |
530 ms |
17264 KB |
Output is correct |
25 |
Correct |
519 ms |
17760 KB |
Output is correct |
26 |
Correct |
590 ms |
18248 KB |
Output is correct |
27 |
Correct |
601 ms |
18248 KB |
Output is correct |
28 |
Correct |
587 ms |
18188 KB |
Output is correct |
29 |
Correct |
584 ms |
18248 KB |
Output is correct |
30 |
Correct |
534 ms |
16456 KB |
Output is correct |
31 |
Correct |
550 ms |
16488 KB |
Output is correct |
32 |
Correct |
554 ms |
16456 KB |
Output is correct |
33 |
Correct |
556 ms |
16456 KB |
Output is correct |
34 |
Correct |
539 ms |
16444 KB |
Output is correct |
35 |
Correct |
543 ms |
16228 KB |
Output is correct |
36 |
Correct |
543 ms |
16328 KB |
Output is correct |
37 |
Correct |
552 ms |
16200 KB |
Output is correct |
38 |
Correct |
541 ms |
16200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8272 KB |
Output is correct |
2 |
Correct |
10 ms |
8272 KB |
Output is correct |
3 |
Correct |
10 ms |
8272 KB |
Output is correct |
4 |
Correct |
11 ms |
8288 KB |
Output is correct |
5 |
Correct |
10 ms |
8272 KB |
Output is correct |
6 |
Correct |
11 ms |
10064 KB |
Output is correct |
7 |
Correct |
12 ms |
10052 KB |
Output is correct |
8 |
Correct |
11 ms |
10064 KB |
Output is correct |
9 |
Correct |
12 ms |
10064 KB |
Output is correct |
10 |
Correct |
12 ms |
8272 KB |
Output is correct |
11 |
Correct |
11 ms |
10064 KB |
Output is correct |
12 |
Correct |
10 ms |
10064 KB |
Output is correct |
13 |
Correct |
11 ms |
8272 KB |
Output is correct |
14 |
Correct |
11 ms |
10064 KB |
Output is correct |
15 |
Correct |
11 ms |
10064 KB |
Output is correct |
16 |
Correct |
6 ms |
8016 KB |
Output is correct |
17 |
Correct |
7 ms |
8016 KB |
Output is correct |
18 |
Correct |
7 ms |
8016 KB |
Output is correct |
19 |
Correct |
7 ms |
8032 KB |
Output is correct |
20 |
Correct |
6 ms |
7772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
545 ms |
16396 KB |
Output is correct |
2 |
Correct |
545 ms |
16392 KB |
Output is correct |
3 |
Correct |
550 ms |
16204 KB |
Output is correct |
4 |
Correct |
551 ms |
16200 KB |
Output is correct |
5 |
Correct |
549 ms |
16196 KB |
Output is correct |
6 |
Correct |
538 ms |
16536 KB |
Output is correct |
7 |
Correct |
536 ms |
16712 KB |
Output is correct |
8 |
Correct |
535 ms |
16712 KB |
Output is correct |
9 |
Correct |
536 ms |
16596 KB |
Output is correct |
10 |
Correct |
537 ms |
16660 KB |
Output is correct |
11 |
Correct |
538 ms |
16712 KB |
Output is correct |
12 |
Correct |
540 ms |
16712 KB |
Output is correct |
13 |
Correct |
536 ms |
16712 KB |
Output is correct |
14 |
Correct |
538 ms |
16712 KB |
Output is correct |
15 |
Correct |
536 ms |
16712 KB |
Output is correct |
16 |
Correct |
99 ms |
13384 KB |
Output is correct |
17 |
Correct |
107 ms |
13508 KB |
Output is correct |
18 |
Correct |
102 ms |
13648 KB |
Output is correct |
19 |
Correct |
108 ms |
13576 KB |
Output is correct |
20 |
Correct |
107 ms |
13640 KB |
Output is correct |
21 |
Correct |
537 ms |
17416 KB |
Output is correct |
22 |
Correct |
531 ms |
17364 KB |
Output is correct |
23 |
Correct |
515 ms |
17224 KB |
Output is correct |
24 |
Correct |
530 ms |
17264 KB |
Output is correct |
25 |
Correct |
519 ms |
17760 KB |
Output is correct |
26 |
Correct |
590 ms |
18248 KB |
Output is correct |
27 |
Correct |
601 ms |
18248 KB |
Output is correct |
28 |
Correct |
587 ms |
18188 KB |
Output is correct |
29 |
Correct |
584 ms |
18248 KB |
Output is correct |
30 |
Correct |
534 ms |
16456 KB |
Output is correct |
31 |
Correct |
550 ms |
16488 KB |
Output is correct |
32 |
Correct |
554 ms |
16456 KB |
Output is correct |
33 |
Correct |
556 ms |
16456 KB |
Output is correct |
34 |
Correct |
539 ms |
16444 KB |
Output is correct |
35 |
Correct |
543 ms |
16228 KB |
Output is correct |
36 |
Correct |
543 ms |
16328 KB |
Output is correct |
37 |
Correct |
552 ms |
16200 KB |
Output is correct |
38 |
Correct |
541 ms |
16200 KB |
Output is correct |
39 |
Correct |
10 ms |
8272 KB |
Output is correct |
40 |
Correct |
10 ms |
8272 KB |
Output is correct |
41 |
Correct |
10 ms |
8272 KB |
Output is correct |
42 |
Correct |
11 ms |
8288 KB |
Output is correct |
43 |
Correct |
10 ms |
8272 KB |
Output is correct |
44 |
Correct |
11 ms |
10064 KB |
Output is correct |
45 |
Correct |
12 ms |
10052 KB |
Output is correct |
46 |
Correct |
11 ms |
10064 KB |
Output is correct |
47 |
Correct |
12 ms |
10064 KB |
Output is correct |
48 |
Correct |
12 ms |
8272 KB |
Output is correct |
49 |
Correct |
11 ms |
10064 KB |
Output is correct |
50 |
Correct |
10 ms |
10064 KB |
Output is correct |
51 |
Correct |
11 ms |
8272 KB |
Output is correct |
52 |
Correct |
11 ms |
10064 KB |
Output is correct |
53 |
Correct |
11 ms |
10064 KB |
Output is correct |
54 |
Correct |
6 ms |
8016 KB |
Output is correct |
55 |
Correct |
7 ms |
8016 KB |
Output is correct |
56 |
Correct |
7 ms |
8016 KB |
Output is correct |
57 |
Correct |
7 ms |
8032 KB |
Output is correct |
58 |
Correct |
6 ms |
7772 KB |
Output is correct |
59 |
Correct |
664 ms |
17772 KB |
Output is correct |
60 |
Correct |
647 ms |
17764 KB |
Output is correct |
61 |
Correct |
644 ms |
17224 KB |
Output is correct |
62 |
Correct |
656 ms |
17480 KB |
Output is correct |
63 |
Correct |
652 ms |
17480 KB |
Output is correct |
64 |
Correct |
760 ms |
18248 KB |
Output is correct |
65 |
Correct |
761 ms |
18368 KB |
Output is correct |
66 |
Correct |
760 ms |
18256 KB |
Output is correct |
67 |
Correct |
765 ms |
18284 KB |
Output is correct |
68 |
Correct |
764 ms |
18248 KB |
Output is correct |
69 |
Correct |
660 ms |
17480 KB |
Output is correct |
70 |
Correct |
649 ms |
18036 KB |
Output is correct |
71 |
Correct |
650 ms |
17992 KB |
Output is correct |
72 |
Correct |
648 ms |
17584 KB |
Output is correct |
73 |
Correct |
652 ms |
17684 KB |
Output is correct |
74 |
Correct |
118 ms |
13644 KB |
Output is correct |
75 |
Correct |
119 ms |
13896 KB |
Output is correct |
76 |
Correct |
118 ms |
13884 KB |
Output is correct |
77 |
Correct |
118 ms |
13896 KB |
Output is correct |
78 |
Correct |
120 ms |
13712 KB |
Output is correct |