답안 #667362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667362 2022-12-01T08:04:38 Z Mahdi Boat (APIO16_boat) C++17
0 / 100
167 ms 8500 KB
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
const int N=505, M=1e9+7;
int n, m, a[N], b[N], dp[N][2*N], c[2*N][N];
vector<int>v;

int tav(int x, int p){
    int res=1;
    while(p){
        if(p&1)
            res=1LL*res*x%M;
        x=1LL*x*x%M;
        p>>=1;
    }
    return res;
}

int main(){
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i]>>b[i];
        v.push_back(a[i]);
        v.push_back(b[i]+1);
    }
    sort(all(v));
    v.resize(distance(v.begin(), unique(all(v))));
    m=v.size()-1;
    for(int i=0;i<m;++i){
        int x=v[i+1]-v[i];
        c[i][0]=1;
        for(int j=1;j<=min(N, x);++j){
            c[i][j]=1LL*c[i][j-1]*(x-j+1)%M;
            c[i][j]=1LL*c[i][j]*tav(j, M-2)%M;
        }
    }
    for(int i=0;i<m;++i)
        dp[0][i]=1;
    for(int i=1;i<=n;++i){
        ll x=dp[i-1][0];
        if(a[i]<=v[0]){
            for(int j=i;j>=1;--j)
                x+=c[0][i-j+1];
        }
        dp[i][0]=x%M;
        for(int j=1;j<m;++j){
            x=dp[i-1][j]+dp[i][j-1];
            x+=M-dp[i-1][j-1];
            if(a[i]<=v[j] && b[i]+1>=v[j+1]){
                for(int k=i;k>=1;--k)
                    x+=1LL*c[j][i-k+1]*dp[k-1][j-1]%M;
            }
            dp[i][j]=x%M;
        }
    }
    cout<<(dp[n][m-1]-1+M)%M<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 164 ms 8500 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 164 ms 8500 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 167 ms 8392 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 164 ms 8500 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -