Submission #310020

# Submission time Handle Problem Language Result Execution time Memory
310020 2020-10-05T10:30:27 Z vipghn2003 Boat (APIO16_boat) C++14
58 / 100
2000 ms 6652 KB
#include<bits/stdc++.h>
using namespace std;

const int N=505;
const int mod=1e9+7;
int n,l[N],r[N],dp[N][N*2],sum[N][N*2],igt[N],gt[N],ways[N*2][N];

int Power(int x,int n)
{
    if(!n) return 1;
    if(n%2) return 1ll*Power(x,n-1)*x%mod;
    int tmp=Power(x,n/2);
    return 1ll*tmp*tmp%mod;
}

void init()
{
    gt[0]=1;
    for(int i=1;i<=N-5;i++) gt[i]=1ll*gt[i-1]*i%mod;
    igt[N-5]=Power(gt[N-5],mod-2);
    for(int i=N-5-1;i>=0;i--) igt[i]=1ll*igt[i+1]*(i+1)%mod;
}

int C(int k,int n)
{
    if(k<0||k>n) return 0;
    if(n<=500) return 1ll*gt[n]*igt[n-k]%mod*igt[k]%mod;
    int res=igt[k];
    for(int i=n-k+1;i<=n;i++) res=1ll*res*i%mod;
    return res;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    init();
    vector<int>val;
    for(int i=1;i<=n;i++)
    {
        cin>>l[i]>>r[i];
        r[i]++;
        val.push_back(l[i]);
        val.push_back(r[i]);
    }
    val.push_back(0);
    sort(val.begin(),val.end());
    val.erase(unique(val.begin(),val.end()),val.end());
    for(int i=1;i<=n;i++)
    {
        l[i]=lower_bound(val.begin(),val.end(),l[i])-val.begin();
        r[i]=lower_bound(val.begin(),val.end(),r[i])-val.begin();
    }
    int sz=val.size()-1;
    for(int i=1;i<=sz-1;i++)
    {
        for(int k=1;k<=n;k++)
        {
            int cur=C(k,val[i+1]-val[i]);
            for(int j=k;j<=n;j++) ways[i][j]=(ways[i][j]+1ll*cur*C(k-1,j-1)%mod)%mod;
        }
    }
    int res=0;
    dp[0][0]=1;
    for(int j=0;j<=sz-1;j++) sum[0][j]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=l[i];j<r[i];j++)
        {
            int cnt=0;
            for(int k=i;k>=1;k--)
            {
                if(val[l[k]]<=val[j]&&val[j+1]<=val[r[k]]);
                else cnt++;
                dp[i][j]=(dp[i][j]+1ll*sum[k-1][j-1]*ways[j][i-k+1-cnt]%mod)%mod;
            }
        }
        for(int j=1;j<=sz-1;j++)
        {
            sum[i][j]=(sum[i][j-1]+dp[i][j])%mod;
        }
        res=(res+sum[i][sz-1])%mod;
    }
    cout<<res;
}

Compilation message

boat.cpp:33:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   33 | main()
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1930 ms 5960 KB Output is correct
2 Correct 1935 ms 6008 KB Output is correct
3 Correct 1936 ms 6148 KB Output is correct
4 Correct 1938 ms 6136 KB Output is correct
5 Correct 1934 ms 6188 KB Output is correct
6 Correct 1926 ms 6512 KB Output is correct
7 Correct 1935 ms 6524 KB Output is correct
8 Correct 1936 ms 6304 KB Output is correct
9 Correct 1941 ms 6652 KB Output is correct
10 Correct 1946 ms 6360 KB Output is correct
11 Correct 1939 ms 6392 KB Output is correct
12 Correct 1937 ms 6360 KB Output is correct
13 Correct 1932 ms 6520 KB Output is correct
14 Correct 1937 ms 6352 KB Output is correct
15 Correct 1946 ms 6376 KB Output is correct
16 Correct 347 ms 4600 KB Output is correct
17 Correct 372 ms 4728 KB Output is correct
18 Correct 355 ms 4608 KB Output is correct
19 Correct 369 ms 4600 KB Output is correct
20 Correct 358 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1930 ms 5960 KB Output is correct
2 Correct 1935 ms 6008 KB Output is correct
3 Correct 1936 ms 6148 KB Output is correct
4 Correct 1938 ms 6136 KB Output is correct
5 Correct 1934 ms 6188 KB Output is correct
6 Correct 1926 ms 6512 KB Output is correct
7 Correct 1935 ms 6524 KB Output is correct
8 Correct 1936 ms 6304 KB Output is correct
9 Correct 1941 ms 6652 KB Output is correct
10 Correct 1946 ms 6360 KB Output is correct
11 Correct 1939 ms 6392 KB Output is correct
12 Correct 1937 ms 6360 KB Output is correct
13 Correct 1932 ms 6520 KB Output is correct
14 Correct 1937 ms 6352 KB Output is correct
15 Correct 1946 ms 6376 KB Output is correct
16 Correct 347 ms 4600 KB Output is correct
17 Correct 372 ms 4728 KB Output is correct
18 Correct 355 ms 4608 KB Output is correct
19 Correct 369 ms 4600 KB Output is correct
20 Correct 358 ms 4600 KB Output is correct
21 Correct 1753 ms 6264 KB Output is correct
22 Correct 1747 ms 6264 KB Output is correct
23 Correct 1704 ms 6264 KB Output is correct
24 Correct 1717 ms 6140 KB Output is correct
25 Correct 1725 ms 6136 KB Output is correct
26 Correct 1803 ms 6264 KB Output is correct
27 Correct 1802 ms 6008 KB Output is correct
28 Correct 1779 ms 6192 KB Output is correct
29 Correct 1768 ms 6136 KB Output is correct
30 Correct 1874 ms 6392 KB Output is correct
31 Correct 1875 ms 6496 KB Output is correct
32 Correct 1872 ms 6460 KB Output is correct
33 Correct 1870 ms 6392 KB Output is correct
34 Correct 1904 ms 6368 KB Output is correct
35 Correct 1871 ms 6100 KB Output is correct
36 Correct 1885 ms 6080 KB Output is correct
37 Correct 1932 ms 6168 KB Output is correct
38 Correct 1882 ms 6356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1528 KB Output is correct
2 Correct 22 ms 1536 KB Output is correct
3 Correct 22 ms 1528 KB Output is correct
4 Correct 22 ms 1536 KB Output is correct
5 Correct 22 ms 1532 KB Output is correct
6 Correct 23 ms 1568 KB Output is correct
7 Correct 23 ms 1536 KB Output is correct
8 Correct 23 ms 1536 KB Output is correct
9 Correct 24 ms 1536 KB Output is correct
10 Correct 24 ms 1536 KB Output is correct
11 Correct 22 ms 1528 KB Output is correct
12 Correct 21 ms 1536 KB Output is correct
13 Correct 23 ms 1536 KB Output is correct
14 Correct 22 ms 1536 KB Output is correct
15 Correct 22 ms 1528 KB Output is correct
16 Correct 13 ms 1408 KB Output is correct
17 Correct 12 ms 1408 KB Output is correct
18 Correct 12 ms 1408 KB Output is correct
19 Correct 13 ms 1408 KB Output is correct
20 Correct 13 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1930 ms 5960 KB Output is correct
2 Correct 1935 ms 6008 KB Output is correct
3 Correct 1936 ms 6148 KB Output is correct
4 Correct 1938 ms 6136 KB Output is correct
5 Correct 1934 ms 6188 KB Output is correct
6 Correct 1926 ms 6512 KB Output is correct
7 Correct 1935 ms 6524 KB Output is correct
8 Correct 1936 ms 6304 KB Output is correct
9 Correct 1941 ms 6652 KB Output is correct
10 Correct 1946 ms 6360 KB Output is correct
11 Correct 1939 ms 6392 KB Output is correct
12 Correct 1937 ms 6360 KB Output is correct
13 Correct 1932 ms 6520 KB Output is correct
14 Correct 1937 ms 6352 KB Output is correct
15 Correct 1946 ms 6376 KB Output is correct
16 Correct 347 ms 4600 KB Output is correct
17 Correct 372 ms 4728 KB Output is correct
18 Correct 355 ms 4608 KB Output is correct
19 Correct 369 ms 4600 KB Output is correct
20 Correct 358 ms 4600 KB Output is correct
21 Correct 1753 ms 6264 KB Output is correct
22 Correct 1747 ms 6264 KB Output is correct
23 Correct 1704 ms 6264 KB Output is correct
24 Correct 1717 ms 6140 KB Output is correct
25 Correct 1725 ms 6136 KB Output is correct
26 Correct 1803 ms 6264 KB Output is correct
27 Correct 1802 ms 6008 KB Output is correct
28 Correct 1779 ms 6192 KB Output is correct
29 Correct 1768 ms 6136 KB Output is correct
30 Correct 1874 ms 6392 KB Output is correct
31 Correct 1875 ms 6496 KB Output is correct
32 Correct 1872 ms 6460 KB Output is correct
33 Correct 1870 ms 6392 KB Output is correct
34 Correct 1904 ms 6368 KB Output is correct
35 Correct 1871 ms 6100 KB Output is correct
36 Correct 1885 ms 6080 KB Output is correct
37 Correct 1932 ms 6168 KB Output is correct
38 Correct 1882 ms 6356 KB Output is correct
39 Correct 22 ms 1528 KB Output is correct
40 Correct 22 ms 1536 KB Output is correct
41 Correct 22 ms 1528 KB Output is correct
42 Correct 22 ms 1536 KB Output is correct
43 Correct 22 ms 1532 KB Output is correct
44 Correct 23 ms 1568 KB Output is correct
45 Correct 23 ms 1536 KB Output is correct
46 Correct 23 ms 1536 KB Output is correct
47 Correct 24 ms 1536 KB Output is correct
48 Correct 24 ms 1536 KB Output is correct
49 Correct 22 ms 1528 KB Output is correct
50 Correct 21 ms 1536 KB Output is correct
51 Correct 23 ms 1536 KB Output is correct
52 Correct 22 ms 1536 KB Output is correct
53 Correct 22 ms 1528 KB Output is correct
54 Correct 13 ms 1408 KB Output is correct
55 Correct 12 ms 1408 KB Output is correct
56 Correct 12 ms 1408 KB Output is correct
57 Correct 13 ms 1408 KB Output is correct
58 Correct 13 ms 1408 KB Output is correct
59 Execution timed out 2051 ms 2316 KB Time limit exceeded
60 Halted 0 ms 0 KB -