#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pb push_back
#define sz(v) (int)v.size()
const int MOD = 998244353;
const int64_t INF = 1e18;
int add(int a,int b){
return (a+b+MOD)%MOD;
}
int mul(int a,int b){
return (1LL*a*b)%MOD;
}
int bigmod(int b,int p){
if(!p) return 1;
int x = bigmod(b,p/2);
x = mul(x,x);
if(p%2) x = mul(x,b);
return x;
}
int vag(int a,int b){
return mul(a,bigmod(b,MOD-2));
}
void getseg(vector<pii> &seg,vector<int> &L,vector<int> &R){
vector<pii> v;
for(auto x:L) v.push_back({x,0});
for(auto x:R) v.push_back({x,1});
sort(all(v));
v.erase(unique(all(v)),v.end());
for(int i=1;i<sz(v);i++){
if(v[i].second == 1){
if(v[i-1].second == 0) seg.push_back({v[i-1].fi,v[i].fi});
else seg.push_back({v[i-1].fi+1,v[i].fi});
}else if(v[i-1].second == 0){
seg.push_back({v[i-1].fi,v[i].fi-1});
}
}
}
int32_t main(){
int n;
cin>>n;
vector<int> L(n),R(n);
for(int i=0;i<n;i++){
cin>>L[i]>>R[i];
}
vector<pii> seg={{-1,-1}};
getseg(seg,L,R);
//for(auto p:seg) cout<<p.fi<<" "<<p.se<<"\n";
int dp[n+1][sz(seg)];
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int j=0;j<sz(seg)-1;j++){
for(int i=0;i<=n;i++){
dp[i][j+1] = add(dp[i][j+1] , dp[i][j]);
int len = seg[j+1].se - seg[j+1].fi + 1;
int tot = 0;
int cnt = 1;
for(int k=1;i+k<=n;k++){
if(L[i+k-1]<=seg[j+1].fi && seg[j+1].se>R[i+k-1] && tot<len){
cnt=mul(cnt,vag(n-k+1,k));
tot++;
}
dp[i+k][j+1] = add(dp[i+k][j+1] , mul(dp[i][j] , cnt));
//cout<<cnt<<endl;
}
}
}
cout<<dp[n][sz(seg)-1];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
469 ms |
2424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
469 ms |
2424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
104 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
469 ms |
2424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |