#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define fi first
#define se second
int const N=5e2+3;
int const A=1e3+3;
int a[N],b[N];
ll unzip[A];
ll dp[N][A];
ll mod =1e9+7;
ll asum(ll n, ll a1=1, ll d=1)
{
return (n*(2*a1+(n-1)*d)/2)%mod;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
cin>>n;
set<int> st;
F0R(i,n)
{
cin>>a[i]>>b[i];
st.insert(a[i]);
st.insert(b[i]);
}
int idx=1;
map<int,int> mp;
trav(e,st)
{
mp[e]=idx;
unzip[idx]=e;
++idx;
}
F0R(i,n)
{
a[i]=mp[a[i]];
b[i]=mp[b[i]];
}
fill(dp[0],dp[0]+A,0);
dp[0][0]=1;
F0R(i,n)
{
fill(dp[i+1],dp[i+1]+A,0);
ll sum=0;
F0R(j,b[i]+1)
{
if(j>a[i])
{
ll r = (unzip[j]-unzip[j-1])%mod;
// choose current but not previous same seg
dp[i+1][j]=sum*(r%mod);
// don't choose current
dp[i+1][j]+=dp[i][j];
// choose current and same seg
dp[i+1][j]+=asum(r-1)*sum;
dp[i+1][j]%=mod;
}
else if(j==a[i])
{
dp[i+1][j]=sum+dp[i][j];
dp[i+1][j]%=mod;
}
else
{
dp[i+1][j]=dp[i][j];
}
sum+=dp[i][j];
sum%=mod;
}
}
ll ans=0;
FOR(j,1,A)
{
ans+=dp[n][j];
ans%=mod;
}
cout<<ans<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |