Submission #653410

# Submission time Handle Problem Language Result Execution time Memory
653410 2022-10-26T18:27:02 Z urosk Boat (APIO16_boat) C++14
9 / 100
167 ms 25580 KB
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}

#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);

using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007LL
ll add(ll x,ll y){
    x+=y;
    if(x<0){
        x%=mod;
        x+=mod;
    }else{
        if(x>=mod) x%=mod;
    }
    return x;
}
ll mul(ll a,ll b){
	ll ans = (a*b)%mod;
	if(ans<0) ans+=mod;
	return ans;
}
ll po(ll x,ll y){
    if(y==0) return 1LL;
    ll ans = po(x,y/2);
    ans = mul(ans,ans);
    if(y&1) ans = mul(ans,x);
    return ans;
}
ll inv(ll x){return po(x,mod-2);}
#define maxn 2005
ll n;
pll a[maxn];
pll seg[maxn];
ll dp[maxn][maxn];
map<pll,ll> ch;
ll cnt = 0;
bool in(pll x,pll y){
    return x.fi>=y.fi&&x.sc<=y.sc;
}
ll calc(ll n,ll k){
    if(ch.count({n,k})){
        //cerr<<"nk: " <<n<<" "<<k<< " "<<ch[{n,k}]<<endl;
        return ch[{n,k}];
    }
    ch[{n,n}] = 1;
    ch[{n,0}] = 1;
    ll ans = 1;
    for(ll j = 1;j<min(n,2001LL);j++){
        ans = mul(ans,n-j+1);
        ans = mul(ans,inv(j));
        ch[{n,j}] = ans;
    }
    //cerr<<"nk: " <<n<<" "<<k<< " "<<ch[{n,k}]<<endl;
    return ch[{n,k}];
}
void tc(){
    cin >> n;
    set<ll> s;
    for(ll i = 1;i<=n;i++){
        cin >> a[i].fi >> a[i].sc;
        s.insert(a[i].fi); s.insert(a[i].sc+1);
    }
    auto it = s.begin(); it++;
    while(it!=s.end()){
        auto it2 = it;
        it2--;
        seg[++cnt] = {(*it2),(*it)-1};
        it++;
    }
    //here;
    //for(ll i = 1;i<=cnt;i++) cerr<<seg[i].fi<<" "<<seg[i].sc<<endl;
    //here;
    dp[0][0] = 1;
    for(ll i = 1;i<=cnt;i++) dp[0][i] = 1;
    for(ll k = 1;k<=cnt;k++){
        dp[1][k] = dp[1][k-1];
        if(in(seg[k],a[1])) dp[1][k] = add(dp[1][k],seg[k].sc-seg[k].fi+1);
    }
    for(ll i = 2;i<=n;i++){
        for(ll k = 1;k<=cnt;k++){
            for(ll j = i;j>=1;j--){
                if(!in(seg[k],a[j])) break;
                dp[i][k] = add(dp[i][k],mul(dp[j-1][k-1],calc(seg[k].sc-seg[k].fi+1,i-j+1)));
                if(j!=1) dp[i][k] = add(dp[i][k],calc(seg[k].sc-seg[k].fi+1,i-j+1));
            }
            dp[i][k] = add(dp[i][k],dp[i-1][k]);
            dp[i][k] = add(dp[i][k],-dp[i-1][k-1]);
        }
        for(ll k = 1;k<=cnt;k++) dp[i][k] = add(dp[i][k],dp[i][k-1]);
    }
    //for(ll i = 1;i<=n;i++) ceri(dp[i],1,cnt);
    ll ans = dp[n][cnt];
    if(n>1) ans = add(ans,dp[n-1][cnt]);
    cout<<dp[n][cnt]<<endl;
}
int main(){
	daj_mi_malo_vremena
    int t; t = 1;
    while(t--){
        tc();
    }
	return 0;
}
//tc1 504
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6240 KB Output is correct
2 Correct 7 ms 6228 KB Output is correct
3 Correct 7 ms 6228 KB Output is correct
4 Correct 7 ms 6228 KB Output is correct
5 Correct 7 ms 6224 KB Output is correct
6 Correct 7 ms 6300 KB Output is correct
7 Correct 7 ms 6224 KB Output is correct
8 Correct 7 ms 6228 KB Output is correct
9 Correct 7 ms 6228 KB Output is correct
10 Correct 8 ms 6228 KB Output is correct
11 Correct 8 ms 6324 KB Output is correct
12 Correct 7 ms 6228 KB Output is correct
13 Correct 7 ms 6232 KB Output is correct
14 Correct 7 ms 6228 KB Output is correct
15 Correct 8 ms 6228 KB Output is correct
16 Correct 3 ms 3028 KB Output is correct
17 Correct 3 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 3 ms 3028 KB Output is correct
20 Correct 3 ms 3032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6240 KB Output is correct
2 Correct 7 ms 6228 KB Output is correct
3 Correct 7 ms 6228 KB Output is correct
4 Correct 7 ms 6228 KB Output is correct
5 Correct 7 ms 6224 KB Output is correct
6 Correct 7 ms 6300 KB Output is correct
7 Correct 7 ms 6224 KB Output is correct
8 Correct 7 ms 6228 KB Output is correct
9 Correct 7 ms 6228 KB Output is correct
10 Correct 8 ms 6228 KB Output is correct
11 Correct 8 ms 6324 KB Output is correct
12 Correct 7 ms 6228 KB Output is correct
13 Correct 7 ms 6232 KB Output is correct
14 Correct 7 ms 6228 KB Output is correct
15 Correct 8 ms 6228 KB Output is correct
16 Correct 3 ms 3028 KB Output is correct
17 Correct 3 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 3 ms 3028 KB Output is correct
20 Correct 3 ms 3032 KB Output is correct
21 Incorrect 40 ms 5928 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 167 ms 25580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6240 KB Output is correct
2 Correct 7 ms 6228 KB Output is correct
3 Correct 7 ms 6228 KB Output is correct
4 Correct 7 ms 6228 KB Output is correct
5 Correct 7 ms 6224 KB Output is correct
6 Correct 7 ms 6300 KB Output is correct
7 Correct 7 ms 6224 KB Output is correct
8 Correct 7 ms 6228 KB Output is correct
9 Correct 7 ms 6228 KB Output is correct
10 Correct 8 ms 6228 KB Output is correct
11 Correct 8 ms 6324 KB Output is correct
12 Correct 7 ms 6228 KB Output is correct
13 Correct 7 ms 6232 KB Output is correct
14 Correct 7 ms 6228 KB Output is correct
15 Correct 8 ms 6228 KB Output is correct
16 Correct 3 ms 3028 KB Output is correct
17 Correct 3 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 3 ms 3028 KB Output is correct
20 Correct 3 ms 3032 KB Output is correct
21 Incorrect 40 ms 5928 KB Output isn't correct
22 Halted 0 ms 0 KB -