# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
667382 |
2022-12-01T08:37:50 Z |
Mahdi |
Boat (APIO16_boat) |
C++17 |
|
290 ms |
7300 KB |
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
const int N=505, M=1e9+7;
int n, m, a[N], b[N], dp[N][2*N], c[2*N][N], en[N][N], h[2*N][N];
vector<int>v;
int tav(int x, int p){
int res=1;
while(p){
if(p&1)
res=1LL*res*x%M;
x=1LL*x*x%M;
p>>=1;
}
return res;
}
void pre(){
en[0][0]=1;
for(int i=1;i<=n;++i){
en[i][0]=1;
for(int j=1;j<=i;++j){
en[i][j]=en[i-1][j]+en[i-1][j-1];
if(en[i][j]>=M)
en[i][j]-=M;
}
}
for(int i=0;i<m;++i){
if(i+1>=v.size()){
for(int i=0;i<N*N;++i){
for(int j=0;j<N*N;++j)
cout<<j<<'\n';
}
}
int x=v[i+1]-v[i];
c[i][0]=1;
for(int j=1;j<=min(n, x);++j){
c[i][j]=1LL*c[i][j-1]*(x-j+1)%M;
c[i][j]=1LL*c[i][j]*tav(j, M-2)%M;
}
}
for(int i=0;i<m;++i){
h[i][1]=c[i][1];
for(int j=2;j<=n;++j){
ll z=0;
for(int k=0;k<=j-2;++k)
z+=1LL*en[j-2][k]*c[i][k+2]%M;
h[i][j]=z%M;
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;++i){
cin>>a[i]>>b[i];
v.push_back(a[i]);
v.push_back(b[i]+1);
}
sort(all(v));
v.resize(int(unique(all(v))-v.begin()));
m=(int)v.size()-1;
pre();
for(int i=0;i<m;++i)
dp[0][i]=1;
for(int i=1;i<=n;++i){
ll x=dp[i-1][0];
if(a[i]<=v[0]){
for(int j=i;j>=1;--j)
x+=h[0][i-j+1];
}
dp[i][0]=x%M;
for(int j=1;j<m;++j){
x=dp[i-1][j]+dp[i][j-1];
x+=M-dp[i-1][j-1];
if(a[i]<=v[j] && b[i]+1>=v[j+1]){
for(int k=i;k>=1;--k)
x+=1LL*h[j][i-k+1]*dp[k-1][j-1]%M;
}
dp[i][j]=x%M;
}
}
cout<<(dp[n][m-1]+M-1)%M<<'\n';
}
Compilation message
boat.cpp: In function 'void pre()':
boat.cpp:34:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | if(i+1>=v.size()){
| ~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
266 ms |
7228 KB |
Output is correct |
2 |
Correct |
273 ms |
7300 KB |
Output is correct |
3 |
Correct |
269 ms |
7128 KB |
Output is correct |
4 |
Correct |
264 ms |
7204 KB |
Output is correct |
5 |
Correct |
270 ms |
7200 KB |
Output is correct |
6 |
Correct |
272 ms |
7200 KB |
Output is correct |
7 |
Correct |
271 ms |
7236 KB |
Output is correct |
8 |
Correct |
268 ms |
7228 KB |
Output is correct |
9 |
Correct |
267 ms |
7276 KB |
Output is correct |
10 |
Correct |
269 ms |
7208 KB |
Output is correct |
11 |
Correct |
265 ms |
7192 KB |
Output is correct |
12 |
Correct |
264 ms |
7160 KB |
Output is correct |
13 |
Correct |
269 ms |
7212 KB |
Output is correct |
14 |
Correct |
269 ms |
7240 KB |
Output is correct |
15 |
Correct |
284 ms |
7208 KB |
Output is correct |
16 |
Correct |
50 ms |
3928 KB |
Output is correct |
17 |
Correct |
52 ms |
3964 KB |
Output is correct |
18 |
Correct |
52 ms |
3960 KB |
Output is correct |
19 |
Correct |
54 ms |
3932 KB |
Output is correct |
20 |
Correct |
51 ms |
3916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
266 ms |
7228 KB |
Output is correct |
2 |
Correct |
273 ms |
7300 KB |
Output is correct |
3 |
Correct |
269 ms |
7128 KB |
Output is correct |
4 |
Correct |
264 ms |
7204 KB |
Output is correct |
5 |
Correct |
270 ms |
7200 KB |
Output is correct |
6 |
Correct |
272 ms |
7200 KB |
Output is correct |
7 |
Correct |
271 ms |
7236 KB |
Output is correct |
8 |
Correct |
268 ms |
7228 KB |
Output is correct |
9 |
Correct |
267 ms |
7276 KB |
Output is correct |
10 |
Correct |
269 ms |
7208 KB |
Output is correct |
11 |
Correct |
265 ms |
7192 KB |
Output is correct |
12 |
Correct |
264 ms |
7160 KB |
Output is correct |
13 |
Correct |
269 ms |
7212 KB |
Output is correct |
14 |
Correct |
269 ms |
7240 KB |
Output is correct |
15 |
Correct |
284 ms |
7208 KB |
Output is correct |
16 |
Correct |
50 ms |
3928 KB |
Output is correct |
17 |
Correct |
52 ms |
3964 KB |
Output is correct |
18 |
Correct |
52 ms |
3960 KB |
Output is correct |
19 |
Correct |
54 ms |
3932 KB |
Output is correct |
20 |
Correct |
51 ms |
3916 KB |
Output is correct |
21 |
Incorrect |
290 ms |
6876 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
1620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
266 ms |
7228 KB |
Output is correct |
2 |
Correct |
273 ms |
7300 KB |
Output is correct |
3 |
Correct |
269 ms |
7128 KB |
Output is correct |
4 |
Correct |
264 ms |
7204 KB |
Output is correct |
5 |
Correct |
270 ms |
7200 KB |
Output is correct |
6 |
Correct |
272 ms |
7200 KB |
Output is correct |
7 |
Correct |
271 ms |
7236 KB |
Output is correct |
8 |
Correct |
268 ms |
7228 KB |
Output is correct |
9 |
Correct |
267 ms |
7276 KB |
Output is correct |
10 |
Correct |
269 ms |
7208 KB |
Output is correct |
11 |
Correct |
265 ms |
7192 KB |
Output is correct |
12 |
Correct |
264 ms |
7160 KB |
Output is correct |
13 |
Correct |
269 ms |
7212 KB |
Output is correct |
14 |
Correct |
269 ms |
7240 KB |
Output is correct |
15 |
Correct |
284 ms |
7208 KB |
Output is correct |
16 |
Correct |
50 ms |
3928 KB |
Output is correct |
17 |
Correct |
52 ms |
3964 KB |
Output is correct |
18 |
Correct |
52 ms |
3960 KB |
Output is correct |
19 |
Correct |
54 ms |
3932 KB |
Output is correct |
20 |
Correct |
51 ms |
3916 KB |
Output is correct |
21 |
Incorrect |
290 ms |
6876 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |