#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define int long long
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define all(a) a.begin(),a.end()
#define pb push_back
const int N=1010,mod=1e9+7;
int n,f[N][N],a[N],b[N],old[N],s[N][N],m;
vector<int> e;
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
//freopen("BOAT.inp","r",stdin);
//freopen("BOAT.out","w",stdout);
cin>>n;
forinc(i,1,n)
{
cin>>a[i]>>b[i];
e.pb(a[i]);e.pb(b[i]);
}
e.erase(unique(all(e)),e.end());
m=e.size();
forinc(i,0,m-1)
{
old[i+1]=e[i];
a[i]=lower_bound(all(e),a[i])-e.begin()+1;
b[i]=lower_bound(all(e),b[i])-e.begin()+1;
}
old[m+1]=1e9;
f[0][0]=1;
forinc(j,0,m) s[0][j]=1;
forinc(i,1,n) forinc(j,0,m)
{
f[i][j]=(f[i][j]+f[i-1][j])%mod;
if(j>=a[i]&&j<=b[i])
{
int c=min(old[b[i]],old[j+1]-1);
f[i][j]=(f[i][j]+s[i-1][j-1]*(c-old[j]+1))%mod;
}
s[i][j]=(s[i][j-1]+f[i][j])%mod;
}
cout<<s[n][m]-1;
}
Compilation message
boat.cpp:13:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
8312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
8312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1528 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
8312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |