답안 #920550

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920550 2024-02-02T17:47:26 Z irmuun Boat (APIO16_boat) C++17
27 / 100
375 ms 524288 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

const ll mod=1e9+7,N=1e3+5;

ll binpow(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1){
            res=res*a%mod;
        }
        a=a*a%mod;
        b=b>>1;
    }
    return res;
}
ll inv(ll a){
    return binpow(a,mod-2);
}

ll fact[N],invfact[N];

void init(){
    fact[0]=1;
    for(ll i=1;i<N;i++){
        fact[i]=fact[i-1]*i%mod;
    }
    invfact[N-1]=inv(fact[N-1]);
    for(ll i=N-1;i>=1;i--){
        invfact[i-1]=invfact[i]*i%mod;
    }
}
ll nCk(ll n,ll k){
    if(k>n||k<0) return 0ll;
    ll res=1;
    for(ll i=n-k+1;i<=n;i++) res=res*i%mod;
    res=res*invfact[k]%mod;
    return res;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    init();
    ll n;
    cin>>n;
    ll a[n+5],b[n+5];
    set<ll>s;
    for(ll i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        s.insert(a[i]);
        s.insert(b[i]+1);
    }
    ll cur=0;
    ll l[2*n+5];
    for(auto x:s){
        cur++;
        l[cur]=x;
    }
    ll dp[n+5][2*n+5][n+5],sum[2*n+5][n+5];
    memset(dp,0,sizeof dp);
    memset(sum,0,sizeof sum);
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ll tot=1;
        for(ll j=1;j<cur;j++){//l[j] l[j+1]-1
            if(b[i]>=l[j]&&a[i]<l[j+1]){
                dp[i][j][1]=tot;
                for(ll k=2;k<=n;k++){
                    dp[i][j][k]=sum[j][k-1];
                }
            }
            for(ll k=1;k<=n;k++){
                tot+=sum[j][k]*nCk(l[j+1]-l[j],k)%mod;
                tot%=mod;
            }
            for(ll k=1;k<=n;k++){
                sum[j][k]+=dp[i][j][k];
                sum[j][k]%=mod;
            }
        }
    }
    for(ll j=1;j<cur;j++){
        for(ll k=1;k<=n;k++){
            ans+=sum[j][k]*nCk(l[j+1]-l[j],k)%mod;
            ans%=mod;
        }
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 294 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 294 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 18312 KB Output is correct
2 Correct 372 ms 18316 KB Output is correct
3 Correct 374 ms 18312 KB Output is correct
4 Correct 371 ms 18264 KB Output is correct
5 Correct 373 ms 18276 KB Output is correct
6 Correct 373 ms 18520 KB Output is correct
7 Correct 373 ms 18264 KB Output is correct
8 Correct 372 ms 18520 KB Output is correct
9 Correct 372 ms 18268 KB Output is correct
10 Correct 373 ms 18312 KB Output is correct
11 Correct 375 ms 18268 KB Output is correct
12 Correct 375 ms 18512 KB Output is correct
13 Correct 373 ms 18264 KB Output is correct
14 Correct 372 ms 18316 KB Output is correct
15 Correct 371 ms 18268 KB Output is correct
16 Correct 167 ms 18268 KB Output is correct
17 Correct 168 ms 18268 KB Output is correct
18 Correct 166 ms 18312 KB Output is correct
19 Correct 171 ms 18316 KB Output is correct
20 Correct 173 ms 18308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 294 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -