Submission #632171

# Submission time Handle Problem Language Result Execution time Memory
632171 2022-08-19T14:54:04 Z bachhoangxuan Boat (APIO16_boat) C++17
0 / 100
6 ms 4308 KB
#include<bits/stdc++.h>
using namespace std;
#define maxn 1005
#define int long long
const int mod=1e9+7;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=(res*a)%mod;
        a=(a*a)%mod;n>>=1;
    }
    return res;
}
vector<int> x;
int n,l[maxn],r[maxn],dp[maxn][maxn],divs[maxn];
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin >> n;divs[0]=1;
    for(int i=1;i<=n;i++){
        cin >> l[i] >> r[i];
        divs[i]=divs[i-1]*power(i,mod-2);
        l[i]-=i;r[i]-=i;r[i]++;
        x.push_back(l[i]);x.push_back(r[i]);
    }
    sort(x.begin(),x.end());
    x.erase(unique(x.begin(),x.end()),x.end());
    int m=(int)x.size();
    for(int i=1;i<=n;i++){
        l[i]=lower_bound(x.begin(),x.end(),l[i])-x.begin()+1;
        r[i]=lower_bound(x.begin(),x.end(),r[i])-x.begin();
    }
    for(int i=0;i<=m;i++) dp[0][i]=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<m;j++){
            dp[i][j]=dp[i][j-1];
            if(j<l[i] || j>r[i]) continue;
            int len=x[j]-x[j-1],mul=1;
            for(int k=i-1;k>=0;k--){
                mul=mul*(len+i-k-1)%mod*divs[i-k]%mod;
                dp[i][j]=(dp[i][j]+dp[k][j-1]*mul)%mod;
            }
        }
        for(int j=0;j<m;j++) dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
    }
    cout << (dp[n][m-1]+mod-1)%mod << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 4308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 4308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 4308 KB Output isn't correct
2 Halted 0 ms 0 KB -