#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define INF (int)(1e9)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MOD = 1e9+7;
int dp1[1001][501],dp2[1001][501]; //boat,group,cnt
int a[501],b[501];
int main()
{
owo
int n;
cin>>n;
vector<int>c;
for(int i=0;i<n;i++){
cin>>a[i]>>b[i];
c.pb(a[i]);
c.pb(b[i]+1);
}
sort(all(c));
c.resize(unique(all(c)) - c.begin());
int m = sz(c),tot = 1;
for(int i=0;i<n;i++){
tot = 1;
for(int j=0;j+1<m;j++){
int s = c[j+1]-c[j];
for(int k=1;k<=min(n,s);k++)dp2[j][k] = dp1[j][k];
if(a[i] <= c[j] && c[j] <= b[i]){
//add you in new group
dp2[j][1] += tot * 1LL * s%MOD;
if(dp2[j][1]>=MOD)dp2[j][1]-=MOD;
if(i){ //add you to existing group
for(int k=2;k<=min(n,s);k++){
dp2[j][k] += dp1[j][k-1] * 1LL * (s-k+1)%MOD;
if(dp2[j][k]>=MOD)dp2[j][k]-=MOD;
}
}
}
for(int k=1;k<=min(n,s);k++){//update tot
tot+=dp1[j][k];
if(tot>=MOD)tot-=MOD;
}
}
for(int j=0;j+1<m;j++){
int s = c[j+1]-c[j];
for(int k=1;k<=min(n,s);k++){
dp1[j][k] = dp2[j][k];
dp2[j][k] = 0;
}
}
}
int ans = 0;
for(int i=0;i<m;i++){
for(int j=1;j<=n;j++){
ans+=dp1[i][j];
ans%=MOD;
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
249 ms |
4244 KB |
Output is correct |
2 |
Correct |
238 ms |
4244 KB |
Output is correct |
3 |
Correct |
230 ms |
4252 KB |
Output is correct |
4 |
Correct |
230 ms |
4248 KB |
Output is correct |
5 |
Correct |
233 ms |
4180 KB |
Output is correct |
6 |
Correct |
237 ms |
4252 KB |
Output is correct |
7 |
Correct |
238 ms |
4180 KB |
Output is correct |
8 |
Correct |
227 ms |
4252 KB |
Output is correct |
9 |
Correct |
232 ms |
4180 KB |
Output is correct |
10 |
Correct |
232 ms |
4244 KB |
Output is correct |
11 |
Correct |
225 ms |
4244 KB |
Output is correct |
12 |
Correct |
224 ms |
4180 KB |
Output is correct |
13 |
Correct |
253 ms |
4308 KB |
Output is correct |
14 |
Correct |
242 ms |
4180 KB |
Output is correct |
15 |
Correct |
230 ms |
4248 KB |
Output is correct |
16 |
Correct |
41 ms |
980 KB |
Output is correct |
17 |
Correct |
49 ms |
980 KB |
Output is correct |
18 |
Correct |
42 ms |
1056 KB |
Output is correct |
19 |
Correct |
44 ms |
980 KB |
Output is correct |
20 |
Correct |
42 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
249 ms |
4244 KB |
Output is correct |
2 |
Correct |
238 ms |
4244 KB |
Output is correct |
3 |
Correct |
230 ms |
4252 KB |
Output is correct |
4 |
Correct |
230 ms |
4248 KB |
Output is correct |
5 |
Correct |
233 ms |
4180 KB |
Output is correct |
6 |
Correct |
237 ms |
4252 KB |
Output is correct |
7 |
Correct |
238 ms |
4180 KB |
Output is correct |
8 |
Correct |
227 ms |
4252 KB |
Output is correct |
9 |
Correct |
232 ms |
4180 KB |
Output is correct |
10 |
Correct |
232 ms |
4244 KB |
Output is correct |
11 |
Correct |
225 ms |
4244 KB |
Output is correct |
12 |
Correct |
224 ms |
4180 KB |
Output is correct |
13 |
Correct |
253 ms |
4308 KB |
Output is correct |
14 |
Correct |
242 ms |
4180 KB |
Output is correct |
15 |
Correct |
230 ms |
4248 KB |
Output is correct |
16 |
Correct |
41 ms |
980 KB |
Output is correct |
17 |
Correct |
49 ms |
980 KB |
Output is correct |
18 |
Correct |
42 ms |
1056 KB |
Output is correct |
19 |
Correct |
44 ms |
980 KB |
Output is correct |
20 |
Correct |
42 ms |
980 KB |
Output is correct |
21 |
Incorrect |
21 ms |
3924 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
249 ms |
4244 KB |
Output is correct |
2 |
Correct |
238 ms |
4244 KB |
Output is correct |
3 |
Correct |
230 ms |
4252 KB |
Output is correct |
4 |
Correct |
230 ms |
4248 KB |
Output is correct |
5 |
Correct |
233 ms |
4180 KB |
Output is correct |
6 |
Correct |
237 ms |
4252 KB |
Output is correct |
7 |
Correct |
238 ms |
4180 KB |
Output is correct |
8 |
Correct |
227 ms |
4252 KB |
Output is correct |
9 |
Correct |
232 ms |
4180 KB |
Output is correct |
10 |
Correct |
232 ms |
4244 KB |
Output is correct |
11 |
Correct |
225 ms |
4244 KB |
Output is correct |
12 |
Correct |
224 ms |
4180 KB |
Output is correct |
13 |
Correct |
253 ms |
4308 KB |
Output is correct |
14 |
Correct |
242 ms |
4180 KB |
Output is correct |
15 |
Correct |
230 ms |
4248 KB |
Output is correct |
16 |
Correct |
41 ms |
980 KB |
Output is correct |
17 |
Correct |
49 ms |
980 KB |
Output is correct |
18 |
Correct |
42 ms |
1056 KB |
Output is correct |
19 |
Correct |
44 ms |
980 KB |
Output is correct |
20 |
Correct |
42 ms |
980 KB |
Output is correct |
21 |
Incorrect |
21 ms |
3924 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |