답안 #487421

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
487421 2021-11-15T13:05:09 Z leaked Boat (APIO16_boat) C++14
0 / 100
616 ms 4300 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define m_p make_pair
#define pb push_back
#define vec vector
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pw(x) (1LL<<(x))
#define fast_iati ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
typedef long long ll;
typedef pair<int,int> pii;
const int M=1e9+7;
const int N=5e2+10;
void add(int &a,int b){
    a+=b;
    if(a>=M) a-=M;
    else if(a<0) a+=M;
}
int mult(int a,int b){
    return 1ll*a*b%M;
}
int binpow(int a,int b){
    int ans=1;
    while(b){
        if(b&1) ans=mult(ans,a);
        b>>=1;a=mult(a,a);
    }
    return ans;
}
int inv[N];
int gi(int x){
    if(!inv[x]) inv[x]=binpow(x,M-2);
    return inv[x];
}
int C(int k,int n){
    if(k>n) return 0;
    int ans=1;
    for(int i=n-k+1;i<=n;i++) ans=mult(ans,i);
    for(int i=1;i<=k;i++) ans=mult(ans,gi(i));
    return ans;
}
signed main(){
    fast_iati;
    int n;
    cin>>n;
    vec<int>a(n),b(n);
    vec<int> kek;
    for(int i=0;i<n;i++) cin>>a[i]>>b[i],kek.pb(a[i]-1),kek.pb(b[i]);
    kek.pb(0);sort(all(kek));kek.erase(unique(all(kek)),kek.end());
    vec<vec<int>>dp(n+1,vec<int>(sz(kek)+1,0));
    vec<int>ways(sz(kek));
    vec<vec<int>>col(sz(kek),vec<int>(n+1,0));
    for(int i=1;i<sz(kek);i++){
        ways[i]=kek[i]-kek[i-1];
        for(int j=1;j<=n;j++){
            col[i][j]=C(j,ways[i]);
//            cout<<"HELLO "<<i<<' '<<ways[i]<<' '<<j<<' '<<col[i][j]<<endl;
        }
    }
    for(int j=0;j<sz(kek);j++) dp[0][j]=1;
    for(int i=0;i<n;i++){
        a[i]=lower_bound(all(kek),a[i]-1)-kek.begin()+1;
        b[i]=lower_bound(all(kek),b[i])-kek.begin();
    }
    for(int i=0;i<n;i++){
        for(int j=a[i];j<=b[i];j++){
            for(int k=i;k>=0;k--){
                if(a[k]>j || b[k]<j) break;
//                cout<<"DEBUG "<<j<<' '<<k<<' '<<i<<' '<<col[j][i-k+1]<<endl;
                add(dp[i+1][j],mult(col[j][i-k+1],dp[k][i-1]));
            }
        }
        add(dp[i+1][0],1);
        for(int j=1;j<sz(kek);j++) add(dp[i+1][j],dp[i+1][j-1]);
    }
    int ans=0;
    for(int j=0;j<=sz(kek);j++) add(ans,dp[n][j]);
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 616 ms 4300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 616 ms 4300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 616 ms 4300 KB Output isn't correct
2 Halted 0 ms 0 KB -