# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
956849 |
2024-04-02T14:43:55 Z |
8pete8 |
Boat (APIO16_boat) |
C++17 |
|
503 ms |
33440 KB |
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<numeric> //gcd(a,b)
#include<cmath>
#include<set>
#include<cassert>
#include<algorithm>
#include<bitset>
#include<stack>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
//#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#define int int64_t
const int mxn=1000+10,minf=-1e18,mod=1e9+7,inf=1e18,lg=30;
int dp[mxn+10][mxn+10],ncr[mxn+10][mxn+10],sum[mxn+10][mxn+10];
int ncr2[mxn+10][mxn+10],choose[mxn+10][mxn+10];
int fac[mxn+10];
inline int in() {
int result = 0;
char ch = getchar_unlocked();
while (true) {
if(ch >= '0' && ch <= '9')
break;
ch = getchar_unlocked();
}
result = ch-'0';
while(true) {
ch = getchar_unlocked();
if (ch < '0' || ch > '9')
break;
result = result*10 + (ch - '0');
}
return result;
}
inline void out(int x) {
int rev=x, c=0;
if(!x) {
putchar_unlocked('0');
return;
}
while(!(rev%10)) {
++c;
rev/=10;
}
rev=0;
while(x) {
rev=rev*10+x%10;
x/=10;
}
while(rev) {
putchar_unlocked(rev%10+'0');
rev/=10;
}
while(c--)
putchar_unlocked('0');
}
int inv(int x){
int ex=mod-2,ans=1;
while(ex){
if(ex&1)ans=(ans*x)%mod;
x=(x*x)%mod;
ex>>=1;
}
return ans;
}
int get(int i,int j){
if(choose[i][j]!=-1)return choose[i][j];
int sum=0;
for(int k=2;k<=j;k++){
int x=(ncr2[i][k]*(ncr[j-2][k-2]))%mod;
if(x)sum=(sum+x)%mod;
else break;
}
choose[i][j]=sum;
return choose[i][j];
}
int32_t main(){
fastio
int n=in();
vector<pii>v(n+1);
vector<int>com;
for(int i=1;i<=n;i++){
v[i].f=in();
v[i].s=in();
v[i].f--;
}
for(int i=1;i<=n;i++)com.pb(v[i].f),com.pb(v[i].s);
sort(all(com));
com.erase(unique(all(com)),com.end());
/*
ncr i,j->(i,j+1)
x=(x*(len-j+1))*inv(j)
*/
ncr[0][0]=1;
for(int i=1;i<=n;i++)for(int j=0;j<=n;j++){
if(j)ncr[i][j]=(ncr[i-1][j]+ncr[i-1][j-1])%mod;
else ncr[i][j]=ncr[i-1][j];
}
for(int i=1;i<com.size();i++){
int len=com[i]-com[i-1];
ncr2[i][1]=len;
for(int j=2;j<=min(n,len);j++)ncr2[i][j]=((ncr2[i][j-1]*(len-j+1))%mod*inv(j))%mod;
}
for(int i=1;i<com.size();i++)for(int j=2;j<=n;j++)choose[i][j]=-1;
for(int i=1;i<com.size();i++)choose[i][1]=ncr2[i][1];
for(int i=0;i<=2*n;i++)sum[0][i]=1;
for(int i=0;i<=2*n;i++)sum[i][0]=1;
for(int i=1;i<=n;i++){
for(int j=1;j<com.size();j++){
if(com[j]>v[i].f&&com[j]<=v[i].s){
if(choose[j][1]==1)dp[i][j]=sum[i-1][j-1];
else{
int cnt=0;
for(int back=i;back>=1;back--){
if(com[j]>v[back].f&&com[j]<=v[back].s){
cnt++;
dp[i][j]=(dp[i][j]+(sum[back-1][j-1]*get(j,cnt))%mod)%mod;
}
}
}
}
sum[i][j]=((dp[i][j]+(sum[i-1][j]+sum[i][j-1])%mod)%mod-sum[i-1][j-1]+mod)%mod;
}
}
out(sum[n][com.size()-1]-1);
}
/*
*/
Compilation message
boat.cpp: In function 'int32_t main()':
boat.cpp:118:15: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
118 | for(int i=1;i<com.size();i++){
| ~^~~~~~~~~~~
boat.cpp:123:15: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
123 | for(int i=1;i<com.size();i++)for(int j=2;j<=n;j++)choose[i][j]=-1;
| ~^~~~~~~~~~~
boat.cpp:124:15: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for(int i=1;i<com.size();i++)choose[i][1]=ncr2[i][1];
| ~^~~~~~~~~~~
boat.cpp:128:16: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
128 | for(int j=1;j<com.size();j++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
31060 KB |
Output is correct |
2 |
Correct |
40 ms |
31312 KB |
Output is correct |
3 |
Correct |
40 ms |
31060 KB |
Output is correct |
4 |
Correct |
40 ms |
31056 KB |
Output is correct |
5 |
Correct |
40 ms |
31060 KB |
Output is correct |
6 |
Correct |
43 ms |
33108 KB |
Output is correct |
7 |
Correct |
40 ms |
33320 KB |
Output is correct |
8 |
Correct |
41 ms |
33112 KB |
Output is correct |
9 |
Correct |
41 ms |
33116 KB |
Output is correct |
10 |
Correct |
40 ms |
33104 KB |
Output is correct |
11 |
Correct |
40 ms |
33028 KB |
Output is correct |
12 |
Correct |
41 ms |
33108 KB |
Output is correct |
13 |
Correct |
41 ms |
33104 KB |
Output is correct |
14 |
Correct |
42 ms |
33020 KB |
Output is correct |
15 |
Correct |
41 ms |
33116 KB |
Output is correct |
16 |
Correct |
11 ms |
23132 KB |
Output is correct |
17 |
Correct |
10 ms |
23128 KB |
Output is correct |
18 |
Correct |
10 ms |
23384 KB |
Output is correct |
19 |
Correct |
11 ms |
23004 KB |
Output is correct |
20 |
Correct |
10 ms |
23132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
31060 KB |
Output is correct |
2 |
Correct |
40 ms |
31312 KB |
Output is correct |
3 |
Correct |
40 ms |
31060 KB |
Output is correct |
4 |
Correct |
40 ms |
31056 KB |
Output is correct |
5 |
Correct |
40 ms |
31060 KB |
Output is correct |
6 |
Correct |
43 ms |
33108 KB |
Output is correct |
7 |
Correct |
40 ms |
33320 KB |
Output is correct |
8 |
Correct |
41 ms |
33112 KB |
Output is correct |
9 |
Correct |
41 ms |
33116 KB |
Output is correct |
10 |
Correct |
40 ms |
33104 KB |
Output is correct |
11 |
Correct |
40 ms |
33028 KB |
Output is correct |
12 |
Correct |
41 ms |
33108 KB |
Output is correct |
13 |
Correct |
41 ms |
33104 KB |
Output is correct |
14 |
Correct |
42 ms |
33020 KB |
Output is correct |
15 |
Correct |
41 ms |
33116 KB |
Output is correct |
16 |
Correct |
11 ms |
23132 KB |
Output is correct |
17 |
Correct |
10 ms |
23128 KB |
Output is correct |
18 |
Correct |
10 ms |
23384 KB |
Output is correct |
19 |
Correct |
11 ms |
23004 KB |
Output is correct |
20 |
Correct |
10 ms |
23132 KB |
Output is correct |
21 |
Correct |
116 ms |
32236 KB |
Output is correct |
22 |
Correct |
109 ms |
32280 KB |
Output is correct |
23 |
Correct |
99 ms |
32340 KB |
Output is correct |
24 |
Correct |
119 ms |
32308 KB |
Output is correct |
25 |
Correct |
123 ms |
32300 KB |
Output is correct |
26 |
Correct |
185 ms |
33108 KB |
Output is correct |
27 |
Correct |
180 ms |
32848 KB |
Output is correct |
28 |
Correct |
214 ms |
33044 KB |
Output is correct |
29 |
Correct |
201 ms |
33052 KB |
Output is correct |
30 |
Correct |
38 ms |
31312 KB |
Output is correct |
31 |
Correct |
40 ms |
31244 KB |
Output is correct |
32 |
Correct |
39 ms |
31312 KB |
Output is correct |
33 |
Correct |
39 ms |
31344 KB |
Output is correct |
34 |
Correct |
38 ms |
31316 KB |
Output is correct |
35 |
Correct |
37 ms |
31244 KB |
Output is correct |
36 |
Correct |
40 ms |
31224 KB |
Output is correct |
37 |
Correct |
39 ms |
31292 KB |
Output is correct |
38 |
Correct |
38 ms |
31244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
15196 KB |
Output is correct |
2 |
Correct |
6 ms |
15196 KB |
Output is correct |
3 |
Correct |
6 ms |
15196 KB |
Output is correct |
4 |
Correct |
7 ms |
15332 KB |
Output is correct |
5 |
Correct |
6 ms |
15196 KB |
Output is correct |
6 |
Correct |
8 ms |
15332 KB |
Output is correct |
7 |
Correct |
8 ms |
15196 KB |
Output is correct |
8 |
Correct |
8 ms |
15196 KB |
Output is correct |
9 |
Correct |
8 ms |
15196 KB |
Output is correct |
10 |
Correct |
9 ms |
15332 KB |
Output is correct |
11 |
Correct |
6 ms |
15264 KB |
Output is correct |
12 |
Correct |
6 ms |
15196 KB |
Output is correct |
13 |
Correct |
6 ms |
15192 KB |
Output is correct |
14 |
Correct |
6 ms |
15192 KB |
Output is correct |
15 |
Correct |
6 ms |
15196 KB |
Output is correct |
16 |
Correct |
4 ms |
15328 KB |
Output is correct |
17 |
Correct |
5 ms |
15192 KB |
Output is correct |
18 |
Correct |
4 ms |
15196 KB |
Output is correct |
19 |
Correct |
4 ms |
15196 KB |
Output is correct |
20 |
Correct |
4 ms |
15452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
31060 KB |
Output is correct |
2 |
Correct |
40 ms |
31312 KB |
Output is correct |
3 |
Correct |
40 ms |
31060 KB |
Output is correct |
4 |
Correct |
40 ms |
31056 KB |
Output is correct |
5 |
Correct |
40 ms |
31060 KB |
Output is correct |
6 |
Correct |
43 ms |
33108 KB |
Output is correct |
7 |
Correct |
40 ms |
33320 KB |
Output is correct |
8 |
Correct |
41 ms |
33112 KB |
Output is correct |
9 |
Correct |
41 ms |
33116 KB |
Output is correct |
10 |
Correct |
40 ms |
33104 KB |
Output is correct |
11 |
Correct |
40 ms |
33028 KB |
Output is correct |
12 |
Correct |
41 ms |
33108 KB |
Output is correct |
13 |
Correct |
41 ms |
33104 KB |
Output is correct |
14 |
Correct |
42 ms |
33020 KB |
Output is correct |
15 |
Correct |
41 ms |
33116 KB |
Output is correct |
16 |
Correct |
11 ms |
23132 KB |
Output is correct |
17 |
Correct |
10 ms |
23128 KB |
Output is correct |
18 |
Correct |
10 ms |
23384 KB |
Output is correct |
19 |
Correct |
11 ms |
23004 KB |
Output is correct |
20 |
Correct |
10 ms |
23132 KB |
Output is correct |
21 |
Correct |
116 ms |
32236 KB |
Output is correct |
22 |
Correct |
109 ms |
32280 KB |
Output is correct |
23 |
Correct |
99 ms |
32340 KB |
Output is correct |
24 |
Correct |
119 ms |
32308 KB |
Output is correct |
25 |
Correct |
123 ms |
32300 KB |
Output is correct |
26 |
Correct |
185 ms |
33108 KB |
Output is correct |
27 |
Correct |
180 ms |
32848 KB |
Output is correct |
28 |
Correct |
214 ms |
33044 KB |
Output is correct |
29 |
Correct |
201 ms |
33052 KB |
Output is correct |
30 |
Correct |
38 ms |
31312 KB |
Output is correct |
31 |
Correct |
40 ms |
31244 KB |
Output is correct |
32 |
Correct |
39 ms |
31312 KB |
Output is correct |
33 |
Correct |
39 ms |
31344 KB |
Output is correct |
34 |
Correct |
38 ms |
31316 KB |
Output is correct |
35 |
Correct |
37 ms |
31244 KB |
Output is correct |
36 |
Correct |
40 ms |
31224 KB |
Output is correct |
37 |
Correct |
39 ms |
31292 KB |
Output is correct |
38 |
Correct |
38 ms |
31244 KB |
Output is correct |
39 |
Correct |
6 ms |
15196 KB |
Output is correct |
40 |
Correct |
6 ms |
15196 KB |
Output is correct |
41 |
Correct |
6 ms |
15196 KB |
Output is correct |
42 |
Correct |
7 ms |
15332 KB |
Output is correct |
43 |
Correct |
6 ms |
15196 KB |
Output is correct |
44 |
Correct |
8 ms |
15332 KB |
Output is correct |
45 |
Correct |
8 ms |
15196 KB |
Output is correct |
46 |
Correct |
8 ms |
15196 KB |
Output is correct |
47 |
Correct |
8 ms |
15196 KB |
Output is correct |
48 |
Correct |
9 ms |
15332 KB |
Output is correct |
49 |
Correct |
6 ms |
15264 KB |
Output is correct |
50 |
Correct |
6 ms |
15196 KB |
Output is correct |
51 |
Correct |
6 ms |
15192 KB |
Output is correct |
52 |
Correct |
6 ms |
15192 KB |
Output is correct |
53 |
Correct |
6 ms |
15196 KB |
Output is correct |
54 |
Correct |
4 ms |
15328 KB |
Output is correct |
55 |
Correct |
5 ms |
15192 KB |
Output is correct |
56 |
Correct |
4 ms |
15196 KB |
Output is correct |
57 |
Correct |
4 ms |
15196 KB |
Output is correct |
58 |
Correct |
4 ms |
15452 KB |
Output is correct |
59 |
Correct |
264 ms |
32244 KB |
Output is correct |
60 |
Correct |
247 ms |
32220 KB |
Output is correct |
61 |
Correct |
247 ms |
32360 KB |
Output is correct |
62 |
Correct |
286 ms |
32336 KB |
Output is correct |
63 |
Correct |
257 ms |
32340 KB |
Output is correct |
64 |
Correct |
474 ms |
33108 KB |
Output is correct |
65 |
Correct |
503 ms |
33440 KB |
Output is correct |
66 |
Correct |
493 ms |
33108 KB |
Output is correct |
67 |
Correct |
470 ms |
33260 KB |
Output is correct |
68 |
Correct |
492 ms |
33224 KB |
Output is correct |
69 |
Correct |
242 ms |
32264 KB |
Output is correct |
70 |
Correct |
227 ms |
32336 KB |
Output is correct |
71 |
Correct |
231 ms |
32596 KB |
Output is correct |
72 |
Correct |
240 ms |
32236 KB |
Output is correct |
73 |
Correct |
243 ms |
32332 KB |
Output is correct |
74 |
Correct |
33 ms |
23388 KB |
Output is correct |
75 |
Correct |
34 ms |
23376 KB |
Output is correct |
76 |
Correct |
33 ms |
23388 KB |
Output is correct |
77 |
Correct |
33 ms |
23332 KB |
Output is correct |
78 |
Correct |
34 ms |
23388 KB |
Output is correct |