#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
// subtask 1 and 2
int const N=5e2+3;
ll a[N],b[N];
ll dp[N][2*N];
ll mod =1e9+7;
ll aps(ll n, ll d)
{
ll cur=1;
ll sum=0;
F0R(i,n)
{
sum+=cur;
sum%=mod;
cur+=d;
cur%=mod;
}
return sum;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
cin>>n;
set<ll> st;
F0R(i,n)
{
cin>>a[i]>>b[i];
--a[i];
st.insert(a[i]);
st.insert(b[i]);
}
st.insert(0);
vi v(all(st));
map<ll,ll>mp;
F0R(i,sz(st))
{
mp[v[i]]=i;
}
F0R(i,n)
{
a[i]=mp[a[i]];
b[i]=mp[b[i]];
}
F0R(j,sz(st)+1)
{
dp[0][j]=1;
}
dp[0][0]=0;
F0R(i,n)
{
F0R(j,sz(st))
{
dp[i+1][j+1]=dp[i][j+1]-dp[i][j];
dp[i+1][j+1]+=mod;
dp[i+1][j+1]%=mod;
}
FOR(j,a[i]+1,b[i]+1)
{
ll l = v[j]-v[j-1];
F0R(k,l)
{
if(i-k<0)break;
ll add = aps(l-k,k) * dp[i-k][j];
add%=mod;
dp[i+1][j+1]+=add;
dp[i+1][j+1]%=mod;
}
}
F0R(j,sz(st))
{
dp[i+1][j+1]+=dp[i+1][j];
dp[i+1][j+1]%=mod;
}
}
ll ans=dp[n][sz(st)]-1;
cout<<ans<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4300 KB |
Output is correct |
2 |
Correct |
8 ms |
4300 KB |
Output is correct |
3 |
Correct |
9 ms |
4312 KB |
Output is correct |
4 |
Correct |
9 ms |
4364 KB |
Output is correct |
5 |
Correct |
9 ms |
4300 KB |
Output is correct |
6 |
Correct |
8 ms |
4300 KB |
Output is correct |
7 |
Correct |
8 ms |
4300 KB |
Output is correct |
8 |
Correct |
9 ms |
4300 KB |
Output is correct |
9 |
Correct |
8 ms |
4300 KB |
Output is correct |
10 |
Correct |
8 ms |
4300 KB |
Output is correct |
11 |
Correct |
8 ms |
4388 KB |
Output is correct |
12 |
Correct |
9 ms |
4300 KB |
Output is correct |
13 |
Correct |
8 ms |
4300 KB |
Output is correct |
14 |
Correct |
8 ms |
4312 KB |
Output is correct |
15 |
Correct |
8 ms |
4300 KB |
Output is correct |
16 |
Correct |
3 ms |
3020 KB |
Output is correct |
17 |
Correct |
3 ms |
3020 KB |
Output is correct |
18 |
Correct |
4 ms |
3020 KB |
Output is correct |
19 |
Correct |
4 ms |
3020 KB |
Output is correct |
20 |
Correct |
3 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4300 KB |
Output is correct |
2 |
Correct |
8 ms |
4300 KB |
Output is correct |
3 |
Correct |
9 ms |
4312 KB |
Output is correct |
4 |
Correct |
9 ms |
4364 KB |
Output is correct |
5 |
Correct |
9 ms |
4300 KB |
Output is correct |
6 |
Correct |
8 ms |
4300 KB |
Output is correct |
7 |
Correct |
8 ms |
4300 KB |
Output is correct |
8 |
Correct |
9 ms |
4300 KB |
Output is correct |
9 |
Correct |
8 ms |
4300 KB |
Output is correct |
10 |
Correct |
8 ms |
4300 KB |
Output is correct |
11 |
Correct |
8 ms |
4388 KB |
Output is correct |
12 |
Correct |
9 ms |
4300 KB |
Output is correct |
13 |
Correct |
8 ms |
4300 KB |
Output is correct |
14 |
Correct |
8 ms |
4312 KB |
Output is correct |
15 |
Correct |
8 ms |
4300 KB |
Output is correct |
16 |
Correct |
3 ms |
3020 KB |
Output is correct |
17 |
Correct |
3 ms |
3020 KB |
Output is correct |
18 |
Correct |
4 ms |
3020 KB |
Output is correct |
19 |
Correct |
4 ms |
3020 KB |
Output is correct |
20 |
Correct |
3 ms |
3028 KB |
Output is correct |
21 |
Incorrect |
70 ms |
4372 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2080 ms |
332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4300 KB |
Output is correct |
2 |
Correct |
8 ms |
4300 KB |
Output is correct |
3 |
Correct |
9 ms |
4312 KB |
Output is correct |
4 |
Correct |
9 ms |
4364 KB |
Output is correct |
5 |
Correct |
9 ms |
4300 KB |
Output is correct |
6 |
Correct |
8 ms |
4300 KB |
Output is correct |
7 |
Correct |
8 ms |
4300 KB |
Output is correct |
8 |
Correct |
9 ms |
4300 KB |
Output is correct |
9 |
Correct |
8 ms |
4300 KB |
Output is correct |
10 |
Correct |
8 ms |
4300 KB |
Output is correct |
11 |
Correct |
8 ms |
4388 KB |
Output is correct |
12 |
Correct |
9 ms |
4300 KB |
Output is correct |
13 |
Correct |
8 ms |
4300 KB |
Output is correct |
14 |
Correct |
8 ms |
4312 KB |
Output is correct |
15 |
Correct |
8 ms |
4300 KB |
Output is correct |
16 |
Correct |
3 ms |
3020 KB |
Output is correct |
17 |
Correct |
3 ms |
3020 KB |
Output is correct |
18 |
Correct |
4 ms |
3020 KB |
Output is correct |
19 |
Correct |
4 ms |
3020 KB |
Output is correct |
20 |
Correct |
3 ms |
3028 KB |
Output is correct |
21 |
Incorrect |
70 ms |
4372 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |