답안 #1106732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106732 2024-10-31T02:02:11 Z 12345678 Boat (APIO16_boat) C++17
36 / 100
2000 ms 12672 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int nx=505, mod=1e9+7;
ll n, a[nx], b[nx], dp[nx][2*nx], qs[nx][2*nx], sz[2*nx], t, pv, ncr[nx][nx], choose[2*nx][nx], l[nx], r[nx];
map<ll, ll> mp;

ll invmod(ll a, ll x)
{
    if (x==0) return 1;
    auto tmp=invmod(a, x/2);
    tmp=(tmp*tmp)%mod;
    if (x%2) return (tmp*a)%mod;
    else return tmp;
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<=n; i++) cin>>a[i]>>b[i], mp[--a[i]]=0, mp[b[i]]=0;
    for (auto &[x, y]:mp) y=t, sz[t]=x-pv, pv=x, t++;
    for (int i=1; i<=n; i++) l[i]=mp[a[i]], r[i]=mp[b[i]];
    ncr[0][0]=1;
    for (int i=1; i<=n; i++)
    {
        for (int j=0; j<=i; j++)
        {
            ncr[i][j]=ncr[i-1][j];
            if (j>0) ncr[i][j]=(ncr[i][j]+ncr[i-1][j-1])%mod;
        }
    }
    for (int i=1; i<t; i++)
    {
        //cout<<"sz "<<i<<' '<<sz[i]<<'\n';
        ll tmp=1;
        choose[i][0]=tmp;
        for (int j=1; j<=min(sz[i], n); j++) tmp=(((tmp*(sz[i]-j+1))%mod)*invmod(j, mod-2))%mod, choose[i][j]=tmp;
    }
    for (int i=1; i<=n; i++)
    {
        //cout<<"l "<<i<<' '<<l[i]<<' '<<r[i]<<'\n';
        for (int j=1; j<t; j++)
        {
            if (l[i]<j&&j<=r[i])
            {
                dp[i][j]=((qs[i-1][j-1]+1)*sz[j])%mod;
                ll cnt=1;
                for (int k=i-1; k>=1; k--)
                {
                    if (l[k]<j&&j<=r[k]) 
                    {
                        cnt++;
                        if (cnt>=2)
                        {
                            ll sm=0;
                            for (int tmp=0; tmp<=cnt-2; tmp++) sm=(sm+choose[j][tmp+2]*ncr[cnt-2][tmp])%mod;
                            //if (i==n) cout<<"sm "<<sm<<'\n', cout<<"choose "<<choose[1][0]<<' '<<ncr[1][0]<<'\n';
                            dp[i][j]=(dp[i][j]+sm*(qs[k-1][j-1]+1))%mod;
                        }
                    }
                }
            }
            //cout<<"dp "<<i<<' '<<j<<' '<<dp[i][j]<<'\n';
            qs[i][j]=((dp[i][j]+qs[i-1][j]+qs[i][j-1]-qs[i-1][j-1])%mod+mod)%mod;
        }
    }
    cout<<qs[n][t-1];
}

/*
2
1 3
1 3
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 12360 KB Output is correct
2 Correct 62 ms 12360 KB Output is correct
3 Correct 56 ms 12360 KB Output is correct
4 Correct 56 ms 12160 KB Output is correct
5 Correct 57 ms 12360 KB Output is correct
6 Correct 56 ms 12660 KB Output is correct
7 Correct 56 ms 12668 KB Output is correct
8 Correct 55 ms 12628 KB Output is correct
9 Correct 56 ms 12616 KB Output is correct
10 Correct 59 ms 12616 KB Output is correct
11 Correct 55 ms 12672 KB Output is correct
12 Correct 55 ms 12616 KB Output is correct
13 Correct 55 ms 12616 KB Output is correct
14 Correct 55 ms 12556 KB Output is correct
15 Correct 55 ms 12664 KB Output is correct
16 Correct 15 ms 11088 KB Output is correct
17 Correct 16 ms 11088 KB Output is correct
18 Correct 16 ms 11088 KB Output is correct
19 Correct 17 ms 11088 KB Output is correct
20 Correct 15 ms 11088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 12360 KB Output is correct
2 Correct 62 ms 12360 KB Output is correct
3 Correct 56 ms 12360 KB Output is correct
4 Correct 56 ms 12160 KB Output is correct
5 Correct 57 ms 12360 KB Output is correct
6 Correct 56 ms 12660 KB Output is correct
7 Correct 56 ms 12668 KB Output is correct
8 Correct 55 ms 12628 KB Output is correct
9 Correct 56 ms 12616 KB Output is correct
10 Correct 59 ms 12616 KB Output is correct
11 Correct 55 ms 12672 KB Output is correct
12 Correct 55 ms 12616 KB Output is correct
13 Correct 55 ms 12616 KB Output is correct
14 Correct 55 ms 12556 KB Output is correct
15 Correct 55 ms 12664 KB Output is correct
16 Correct 15 ms 11088 KB Output is correct
17 Correct 16 ms 11088 KB Output is correct
18 Correct 16 ms 11088 KB Output is correct
19 Correct 17 ms 11088 KB Output is correct
20 Correct 15 ms 11088 KB Output is correct
21 Execution timed out 2058 ms 12304 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 5712 KB Output is correct
2 Correct 9 ms 5848 KB Output is correct
3 Correct 13 ms 5712 KB Output is correct
4 Correct 12 ms 5712 KB Output is correct
5 Correct 14 ms 5712 KB Output is correct
6 Correct 32 ms 7572 KB Output is correct
7 Correct 32 ms 7504 KB Output is correct
8 Correct 32 ms 7504 KB Output is correct
9 Correct 36 ms 7504 KB Output is correct
10 Correct 32 ms 5712 KB Output is correct
11 Correct 14 ms 7504 KB Output is correct
12 Correct 10 ms 7504 KB Output is correct
13 Correct 11 ms 5712 KB Output is correct
14 Correct 11 ms 7672 KB Output is correct
15 Correct 13 ms 7564 KB Output is correct
16 Correct 9 ms 5712 KB Output is correct
17 Correct 7 ms 5712 KB Output is correct
18 Correct 8 ms 5736 KB Output is correct
19 Correct 7 ms 5712 KB Output is correct
20 Correct 9 ms 5712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 12360 KB Output is correct
2 Correct 62 ms 12360 KB Output is correct
3 Correct 56 ms 12360 KB Output is correct
4 Correct 56 ms 12160 KB Output is correct
5 Correct 57 ms 12360 KB Output is correct
6 Correct 56 ms 12660 KB Output is correct
7 Correct 56 ms 12668 KB Output is correct
8 Correct 55 ms 12628 KB Output is correct
9 Correct 56 ms 12616 KB Output is correct
10 Correct 59 ms 12616 KB Output is correct
11 Correct 55 ms 12672 KB Output is correct
12 Correct 55 ms 12616 KB Output is correct
13 Correct 55 ms 12616 KB Output is correct
14 Correct 55 ms 12556 KB Output is correct
15 Correct 55 ms 12664 KB Output is correct
16 Correct 15 ms 11088 KB Output is correct
17 Correct 16 ms 11088 KB Output is correct
18 Correct 16 ms 11088 KB Output is correct
19 Correct 17 ms 11088 KB Output is correct
20 Correct 15 ms 11088 KB Output is correct
21 Execution timed out 2058 ms 12304 KB Time limit exceeded
22 Halted 0 ms 0 KB -