답안 #82429

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82429 2018-10-30T14:58:20 Z Bodo171 Boat (APIO16_boat) C++14
100 / 100
506 ms 1504 KB
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
const int nmax=505;
const long long mod=1000*1000*1000+7;
long long fact[nmax],inv[nmax],dp[nmax],C[nmax],sum[nmax],combi[nmax];
long long cc,ans;
int st[nmax],dr[nmax],v[2*nmax],spec[nmax];
int n,i,nr,j,k;
long long expo(long long A,long long B)
{
    long long ret=1,p2=A;
    for(int p=0;p<=30;p++)
    {
        if(((1<<p)&B))
        {
            ret=(1LL*ret*p2)%mod;
        }
        p2=(1LL*p2*p2)%mod;
    }
    return ret;
}
void precinv()
{
    fact[0]=1;
    for(long long i=1;i<=n;i++)
        fact[i]=(1LL*fact[i-1]*i)%mod;
    inv[n]=expo(fact[n],mod-2);
    for(long long i=n-1;i>=0;i--)
        inv[i]=(1LL*inv[i+1]*(i+1))%mod;
}
void calcC(int len)
{
    long long F=1;
    C[0]=1;
    for(long long i=len;i>=max(len-n+1,0);i--)
    {
        F=(1LL*F*i)%mod;
        C[len-i+1]=(1LL*F*inv[len-i+1])%mod;
    }
}
long long c(int A,int B)
{
    return (1LL*fact[A]*((1LL*inv[B]*inv[A-B])%mod))%mod;
}
int main()
{
    //freopen("data.in","r",stdin);
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>st[i]>>dr[i];
        v[++nr]=st[i];
        v[++nr]=dr[i]+1;
    }
    sort(v+1,v+nr+1);
    precinv();
    for(int cnt=1;cnt<2*n;cnt++)
        if(v[cnt]<v[cnt+1])
    {
        nr=0;sum[0]=1;
        for(j=1;j<=n;j++)
        {
            if(st[j]<=v[cnt]&&dr[j]>=v[cnt+1]-1)
                spec[++nr]=j;
            sum[j]=(1LL*sum[j-1]+dp[j])%mod;
        }
        calcC(v[cnt+1]-v[cnt]);
        combi[0]=1;C[0]=1;
        for(i=3;i<=nr;i++)
        {
            combi[i]=0;
            for(j=0;j<=i-2;j++)
           {
                combi[i]=(1LL*combi[i]+1LL*c(i-2,j)*C[j+2])%mod;
           }
        }
        combi[1]=C[1];
        combi[2]=C[2];
        for(int i=1;i<=nr;i++)
          for(int j=i;j<=nr;j++)
        {
            cc=sum[spec[i]-1];
            dp[spec[j]]=(dp[spec[j]]+1LL*cc*combi[j-i+1])%mod;
        }
        for(i=1;i<=n;i++)
            C[i]=0;
    }
    for(i=1;i<=n;i++)
        ans=(ans+dp[i])%mod;
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 7 ms 452 KB Output is correct
3 Correct 7 ms 456 KB Output is correct
4 Correct 8 ms 532 KB Output is correct
5 Correct 8 ms 704 KB Output is correct
6 Correct 7 ms 704 KB Output is correct
7 Correct 7 ms 704 KB Output is correct
8 Correct 7 ms 704 KB Output is correct
9 Correct 7 ms 704 KB Output is correct
10 Correct 7 ms 704 KB Output is correct
11 Correct 7 ms 704 KB Output is correct
12 Correct 7 ms 704 KB Output is correct
13 Correct 7 ms 704 KB Output is correct
14 Correct 7 ms 704 KB Output is correct
15 Correct 7 ms 704 KB Output is correct
16 Correct 4 ms 704 KB Output is correct
17 Correct 4 ms 704 KB Output is correct
18 Correct 3 ms 704 KB Output is correct
19 Correct 3 ms 704 KB Output is correct
20 Correct 3 ms 704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 7 ms 452 KB Output is correct
3 Correct 7 ms 456 KB Output is correct
4 Correct 8 ms 532 KB Output is correct
5 Correct 8 ms 704 KB Output is correct
6 Correct 7 ms 704 KB Output is correct
7 Correct 7 ms 704 KB Output is correct
8 Correct 7 ms 704 KB Output is correct
9 Correct 7 ms 704 KB Output is correct
10 Correct 7 ms 704 KB Output is correct
11 Correct 7 ms 704 KB Output is correct
12 Correct 7 ms 704 KB Output is correct
13 Correct 7 ms 704 KB Output is correct
14 Correct 7 ms 704 KB Output is correct
15 Correct 7 ms 704 KB Output is correct
16 Correct 4 ms 704 KB Output is correct
17 Correct 4 ms 704 KB Output is correct
18 Correct 3 ms 704 KB Output is correct
19 Correct 3 ms 704 KB Output is correct
20 Correct 3 ms 704 KB Output is correct
21 Correct 180 ms 800 KB Output is correct
22 Correct 175 ms 800 KB Output is correct
23 Correct 153 ms 920 KB Output is correct
24 Correct 168 ms 920 KB Output is correct
25 Correct 179 ms 920 KB Output is correct
26 Correct 394 ms 920 KB Output is correct
27 Correct 407 ms 920 KB Output is correct
28 Correct 394 ms 920 KB Output is correct
29 Correct 392 ms 924 KB Output is correct
30 Correct 7 ms 924 KB Output is correct
31 Correct 7 ms 924 KB Output is correct
32 Correct 7 ms 928 KB Output is correct
33 Correct 8 ms 940 KB Output is correct
34 Correct 8 ms 1092 KB Output is correct
35 Correct 9 ms 1092 KB Output is correct
36 Correct 8 ms 1092 KB Output is correct
37 Correct 7 ms 1092 KB Output is correct
38 Correct 7 ms 1092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1092 KB Output is correct
2 Correct 4 ms 1092 KB Output is correct
3 Correct 5 ms 1092 KB Output is correct
4 Correct 5 ms 1092 KB Output is correct
5 Correct 5 ms 1092 KB Output is correct
6 Correct 6 ms 1092 KB Output is correct
7 Correct 6 ms 1092 KB Output is correct
8 Correct 6 ms 1092 KB Output is correct
9 Correct 20 ms 1092 KB Output is correct
10 Correct 6 ms 1092 KB Output is correct
11 Correct 4 ms 1092 KB Output is correct
12 Correct 4 ms 1092 KB Output is correct
13 Correct 4 ms 1092 KB Output is correct
14 Correct 4 ms 1092 KB Output is correct
15 Correct 6 ms 1092 KB Output is correct
16 Correct 3 ms 1092 KB Output is correct
17 Correct 4 ms 1092 KB Output is correct
18 Correct 3 ms 1096 KB Output is correct
19 Correct 3 ms 1096 KB Output is correct
20 Correct 3 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 7 ms 452 KB Output is correct
3 Correct 7 ms 456 KB Output is correct
4 Correct 8 ms 532 KB Output is correct
5 Correct 8 ms 704 KB Output is correct
6 Correct 7 ms 704 KB Output is correct
7 Correct 7 ms 704 KB Output is correct
8 Correct 7 ms 704 KB Output is correct
9 Correct 7 ms 704 KB Output is correct
10 Correct 7 ms 704 KB Output is correct
11 Correct 7 ms 704 KB Output is correct
12 Correct 7 ms 704 KB Output is correct
13 Correct 7 ms 704 KB Output is correct
14 Correct 7 ms 704 KB Output is correct
15 Correct 7 ms 704 KB Output is correct
16 Correct 4 ms 704 KB Output is correct
17 Correct 4 ms 704 KB Output is correct
18 Correct 3 ms 704 KB Output is correct
19 Correct 3 ms 704 KB Output is correct
20 Correct 3 ms 704 KB Output is correct
21 Correct 180 ms 800 KB Output is correct
22 Correct 175 ms 800 KB Output is correct
23 Correct 153 ms 920 KB Output is correct
24 Correct 168 ms 920 KB Output is correct
25 Correct 179 ms 920 KB Output is correct
26 Correct 394 ms 920 KB Output is correct
27 Correct 407 ms 920 KB Output is correct
28 Correct 394 ms 920 KB Output is correct
29 Correct 392 ms 924 KB Output is correct
30 Correct 7 ms 924 KB Output is correct
31 Correct 7 ms 924 KB Output is correct
32 Correct 7 ms 928 KB Output is correct
33 Correct 8 ms 940 KB Output is correct
34 Correct 8 ms 1092 KB Output is correct
35 Correct 9 ms 1092 KB Output is correct
36 Correct 8 ms 1092 KB Output is correct
37 Correct 7 ms 1092 KB Output is correct
38 Correct 7 ms 1092 KB Output is correct
39 Correct 4 ms 1092 KB Output is correct
40 Correct 4 ms 1092 KB Output is correct
41 Correct 5 ms 1092 KB Output is correct
42 Correct 5 ms 1092 KB Output is correct
43 Correct 5 ms 1092 KB Output is correct
44 Correct 6 ms 1092 KB Output is correct
45 Correct 6 ms 1092 KB Output is correct
46 Correct 6 ms 1092 KB Output is correct
47 Correct 20 ms 1092 KB Output is correct
48 Correct 6 ms 1092 KB Output is correct
49 Correct 4 ms 1092 KB Output is correct
50 Correct 4 ms 1092 KB Output is correct
51 Correct 4 ms 1092 KB Output is correct
52 Correct 4 ms 1092 KB Output is correct
53 Correct 6 ms 1092 KB Output is correct
54 Correct 3 ms 1092 KB Output is correct
55 Correct 4 ms 1092 KB Output is correct
56 Correct 3 ms 1096 KB Output is correct
57 Correct 3 ms 1096 KB Output is correct
58 Correct 3 ms 1100 KB Output is correct
59 Correct 198 ms 1132 KB Output is correct
60 Correct 183 ms 1132 KB Output is correct
61 Correct 168 ms 1152 KB Output is correct
62 Correct 205 ms 1168 KB Output is correct
63 Correct 182 ms 1168 KB Output is correct
64 Correct 444 ms 1168 KB Output is correct
65 Correct 457 ms 1200 KB Output is correct
66 Correct 463 ms 1200 KB Output is correct
67 Correct 506 ms 1208 KB Output is correct
68 Correct 433 ms 1224 KB Output is correct
69 Correct 179 ms 1236 KB Output is correct
70 Correct 167 ms 1248 KB Output is correct
71 Correct 164 ms 1260 KB Output is correct
72 Correct 176 ms 1404 KB Output is correct
73 Correct 176 ms 1404 KB Output is correct
74 Correct 39 ms 1404 KB Output is correct
75 Correct 39 ms 1404 KB Output is correct
76 Correct 39 ms 1404 KB Output is correct
77 Correct 40 ms 1492 KB Output is correct
78 Correct 41 ms 1504 KB Output is correct