| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1285304 | hainam2k9 | Boat (APIO16_boat) | C++20 | 241 ms | 4544 KiB |
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 1e5+5;
const string NAME = "";
int n,dp[1005][505],f[1005][505],rs=0;
pair<int,int> p[505];
vector<int> v;
void add(int& a, int b){
a+=b;
if(a>=MOD) a-=MOD;
}
int modpow(int a, int b){
if(b==0) return 1;
ll half=modpow(a,b>>1);
half=(half*half)%MOD;
if(b&1) return(half*a)%MOD;
return half;
}
int main()
{
tt;
if(fopen((NAME + ".INP").c_str(), "r")) fo;
cin >> n;
for(int i = 1; i<=n; ++i)
cin >> p[i].fi >> p[i].se, v.pb(p[i].fi), v.pb(p[i].se+1);
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
for(int i = 0; i<sz(v); ++i){
dp[i][0]=1;
int cur=v[i], nxt=v[i];
if(i<sz(v)-1) nxt=v[i+1]-1;
f[i][0]=1;
for(int j = 1; j<=n; ++j)
f[i][j]=(1ll*f[i][j-1]*(nxt-cur+j)%MOD)*modpow(j,MOD-2)%MOD;
}
for(int i = 0; i<sz(v)-1; ++i){
int cur=v[i], nxt=v[i+1]-1;
for(int j = 1; j<=n; ++j){
if(i>0) dp[i][j]=dp[i-1][j];
if(p[j].fi>cur||p[j].se<nxt) continue;
int cnt=1;
for(int k = j-1; k>=0; --k){
add(dp[i][j],1ll*dp[i-1][k]*f[i][cnt]%MOD);
if(p[k].fi<=cur&&p[k].se>=nxt) ++cnt;
}
if(i==0) add(dp[i][j],f[i][cnt]);
}
}
for(int i = 1; i<=n; ++i)
add(rs,dp[sz(v)-2][i]);
cout << rs;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
