답안 #48063

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48063 2018-05-09T18:16:03 Z shirowa Boat (APIO16_boat) C++14
100 / 100
1253 ms 13392 KB
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
long long p;

long long rui(long long x,long long y){
    if(y==0)return 1;
    if(y==1)return x;
    if(y==2)return x*x%p;
    if(y%2==0)return rui(rui(x,y/2),2)%p;
    if(y%2==1)return (rui(rui(x,(y-1)/2),2)%p)*x%p;
}


int main(void){
    p=1000000007;
    long long n;
    scanf("%lld",&n);
    long long a[n],b[n];
    for(int i=0;i<n;i++){
        scanf("%lld%lld",&a[i],&b[i]);
    }
    long long kai[505];
    kai[0]=1;
    for(int i=1;i<505;i++){
        kai[i]=i*kai[i-1]%p;
    }long long inv[505];
    for(int i=0;i<505;i++){
        inv[i]=rui(kai[i],p-2);
    }
    long long dd[1005];
    for(int i=0;i<1005;i++){
        dd[i]=2000000000;
    }
    for(int i=0;i<n;i++){
        dd[i]=a[i];
        dd[i+n]=b[i]+1;
    }
    sort(dd,dd+1005);
    for(int i=1;i<1005;i++){
        if(dd[i]==dd[i-1])dd[i]=2000000000;
    }
    sort(dd,dd+1005);
    int m;m=0;
    for(int i=0;i<1005;i++){
        if(dd[i]<1500000000)m++;
    }
    long long d[m];
    for(int i=0;i<m;i++){
        d[i]=dd[i];
    }
    bool e[n][m-1];
    for(int i=0;i<n;i++){
        for(int j=0;j<m-1;j++){
            e[i][j]=false;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m-1;j++){
            if(a[i]<=d[j]&&d[j+1]-1<=b[i]){
                e[i][j]=true;
            }
        }
    }
    long long ll[m-1];
    for(int i=0;i<m-1;i++){
        ll[i]=d[i+1]-d[i];
    }
    long long c[m-1][505];
    long long s,t;
    for(int i=0;i<m-1;i++){
        s=ll[i]-1;
        c[i][0]=1;
        for(int j=1;j<505;j++){
            c[i][j]=(s*inv[j])%p;
            if(j==1)c[i][j]=ll[i];
            t=s*(ll[i]-1+j)%p;
            s=t;
        }
    }
    long long dp[n][m];
    long long sum[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            dp[i][j]=0;
            sum[i][j]=0;
        }
    }
    dp[0][0]=1;
    for(int i=0;i<m-1;i++){
        if(e[0][i])dp[0][i+1]=ll[i];
    }
    sum[0][0]=dp[0][0];
    for(int i=1;i<m;i++){
        sum[0][i]=(sum[0][i-1]+dp[0][i])%p;
    }
    long long x,y,z;
    for(int i=1;i<n;i++){
        dp[i][0]=dp[i-1][0];
        for(int j=1;j<m;j++){
            dp[i][j]=dp[i-1][j];
            if(e[i][j-1]){
                x=1;
                y=i;
                while(1<=y){
                    if(e[y][j-1]){
                        dp[i][j]+=c[j-1][x]*sum[y-1][j-1]%p;
                        if(dp[i][j]>=p)dp[i][j]-=p;
                        x++;y--;
                    }
                    else y--;
                }
                if(e[0][j-1])dp[i][j]+=c[j-1][x]%p;
                if(dp[i][j]>=p)dp[i][j]-=p;
            }
        }
        sum[i][0]=dp[i][0];
        for(int j=1;j<m;j++){
            sum[i][j]=(sum[i][j-1]+dp[i][j])%p;
        }
    }
    sum[n-1][m-1]+=p;
    printf("%lld\n",(sum[n-1][m-1]-1)%p);
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:98:19: warning: unused variable 'z' [-Wunused-variable]
     long long x,y,z;
                   ^
boat.cpp: In function 'long long int rui(long long int, long long int)':
boat.cpp:13:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
boat.cpp: In function 'int main()':
boat.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
boat.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld",&a[i],&b[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 12668 KB Output is correct
2 Correct 36 ms 12756 KB Output is correct
3 Correct 35 ms 12756 KB Output is correct
4 Correct 35 ms 12756 KB Output is correct
5 Correct 36 ms 12756 KB Output is correct
6 Correct 39 ms 12756 KB Output is correct
7 Correct 41 ms 12756 KB Output is correct
8 Correct 36 ms 12864 KB Output is correct
9 Correct 38 ms 12864 KB Output is correct
10 Correct 35 ms 12912 KB Output is correct
11 Correct 36 ms 12912 KB Output is correct
12 Correct 35 ms 12912 KB Output is correct
13 Correct 35 ms 12912 KB Output is correct
14 Correct 35 ms 12912 KB Output is correct
15 Correct 35 ms 12912 KB Output is correct
16 Correct 22 ms 12912 KB Output is correct
17 Correct 22 ms 12912 KB Output is correct
18 Correct 22 ms 12912 KB Output is correct
19 Correct 21 ms 12912 KB Output is correct
20 Correct 22 ms 12912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 12668 KB Output is correct
2 Correct 36 ms 12756 KB Output is correct
3 Correct 35 ms 12756 KB Output is correct
4 Correct 35 ms 12756 KB Output is correct
5 Correct 36 ms 12756 KB Output is correct
6 Correct 39 ms 12756 KB Output is correct
7 Correct 41 ms 12756 KB Output is correct
8 Correct 36 ms 12864 KB Output is correct
9 Correct 38 ms 12864 KB Output is correct
10 Correct 35 ms 12912 KB Output is correct
11 Correct 36 ms 12912 KB Output is correct
12 Correct 35 ms 12912 KB Output is correct
13 Correct 35 ms 12912 KB Output is correct
14 Correct 35 ms 12912 KB Output is correct
15 Correct 35 ms 12912 KB Output is correct
16 Correct 22 ms 12912 KB Output is correct
17 Correct 22 ms 12912 KB Output is correct
18 Correct 22 ms 12912 KB Output is correct
19 Correct 21 ms 12912 KB Output is correct
20 Correct 22 ms 12912 KB Output is correct
21 Correct 642 ms 12912 KB Output is correct
22 Correct 630 ms 12912 KB Output is correct
23 Correct 573 ms 12912 KB Output is correct
24 Correct 616 ms 12912 KB Output is correct
25 Correct 611 ms 12912 KB Output is correct
26 Correct 945 ms 12912 KB Output is correct
27 Correct 969 ms 12912 KB Output is correct
28 Correct 975 ms 12912 KB Output is correct
29 Correct 971 ms 12912 KB Output is correct
30 Correct 44 ms 12912 KB Output is correct
31 Correct 36 ms 13000 KB Output is correct
32 Correct 36 ms 13000 KB Output is correct
33 Correct 36 ms 13024 KB Output is correct
34 Correct 36 ms 13024 KB Output is correct
35 Correct 36 ms 13024 KB Output is correct
36 Correct 36 ms 13024 KB Output is correct
37 Correct 36 ms 13024 KB Output is correct
38 Correct 46 ms 13024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 13024 KB Output is correct
2 Correct 10 ms 13024 KB Output is correct
3 Correct 11 ms 13024 KB Output is correct
4 Correct 11 ms 13024 KB Output is correct
5 Correct 11 ms 13024 KB Output is correct
6 Correct 15 ms 13024 KB Output is correct
7 Correct 15 ms 13024 KB Output is correct
8 Correct 15 ms 13024 KB Output is correct
9 Correct 15 ms 13024 KB Output is correct
10 Correct 15 ms 13024 KB Output is correct
11 Correct 11 ms 13024 KB Output is correct
12 Correct 9 ms 13024 KB Output is correct
13 Correct 10 ms 13024 KB Output is correct
14 Correct 10 ms 13024 KB Output is correct
15 Correct 11 ms 13024 KB Output is correct
16 Correct 8 ms 13024 KB Output is correct
17 Correct 8 ms 13024 KB Output is correct
18 Correct 8 ms 13024 KB Output is correct
19 Correct 8 ms 13024 KB Output is correct
20 Correct 11 ms 13024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 12668 KB Output is correct
2 Correct 36 ms 12756 KB Output is correct
3 Correct 35 ms 12756 KB Output is correct
4 Correct 35 ms 12756 KB Output is correct
5 Correct 36 ms 12756 KB Output is correct
6 Correct 39 ms 12756 KB Output is correct
7 Correct 41 ms 12756 KB Output is correct
8 Correct 36 ms 12864 KB Output is correct
9 Correct 38 ms 12864 KB Output is correct
10 Correct 35 ms 12912 KB Output is correct
11 Correct 36 ms 12912 KB Output is correct
12 Correct 35 ms 12912 KB Output is correct
13 Correct 35 ms 12912 KB Output is correct
14 Correct 35 ms 12912 KB Output is correct
15 Correct 35 ms 12912 KB Output is correct
16 Correct 22 ms 12912 KB Output is correct
17 Correct 22 ms 12912 KB Output is correct
18 Correct 22 ms 12912 KB Output is correct
19 Correct 21 ms 12912 KB Output is correct
20 Correct 22 ms 12912 KB Output is correct
21 Correct 642 ms 12912 KB Output is correct
22 Correct 630 ms 12912 KB Output is correct
23 Correct 573 ms 12912 KB Output is correct
24 Correct 616 ms 12912 KB Output is correct
25 Correct 611 ms 12912 KB Output is correct
26 Correct 945 ms 12912 KB Output is correct
27 Correct 969 ms 12912 KB Output is correct
28 Correct 975 ms 12912 KB Output is correct
29 Correct 971 ms 12912 KB Output is correct
30 Correct 44 ms 12912 KB Output is correct
31 Correct 36 ms 13000 KB Output is correct
32 Correct 36 ms 13000 KB Output is correct
33 Correct 36 ms 13024 KB Output is correct
34 Correct 36 ms 13024 KB Output is correct
35 Correct 36 ms 13024 KB Output is correct
36 Correct 36 ms 13024 KB Output is correct
37 Correct 36 ms 13024 KB Output is correct
38 Correct 46 ms 13024 KB Output is correct
39 Correct 11 ms 13024 KB Output is correct
40 Correct 10 ms 13024 KB Output is correct
41 Correct 11 ms 13024 KB Output is correct
42 Correct 11 ms 13024 KB Output is correct
43 Correct 11 ms 13024 KB Output is correct
44 Correct 15 ms 13024 KB Output is correct
45 Correct 15 ms 13024 KB Output is correct
46 Correct 15 ms 13024 KB Output is correct
47 Correct 15 ms 13024 KB Output is correct
48 Correct 15 ms 13024 KB Output is correct
49 Correct 11 ms 13024 KB Output is correct
50 Correct 9 ms 13024 KB Output is correct
51 Correct 10 ms 13024 KB Output is correct
52 Correct 10 ms 13024 KB Output is correct
53 Correct 11 ms 13024 KB Output is correct
54 Correct 8 ms 13024 KB Output is correct
55 Correct 8 ms 13024 KB Output is correct
56 Correct 8 ms 13024 KB Output is correct
57 Correct 8 ms 13024 KB Output is correct
58 Correct 11 ms 13024 KB Output is correct
59 Correct 745 ms 13224 KB Output is correct
60 Correct 670 ms 13224 KB Output is correct
61 Correct 626 ms 13248 KB Output is correct
62 Correct 743 ms 13248 KB Output is correct
63 Correct 712 ms 13248 KB Output is correct
64 Correct 1207 ms 13280 KB Output is correct
65 Correct 1206 ms 13280 KB Output is correct
66 Correct 1211 ms 13300 KB Output is correct
67 Correct 1192 ms 13300 KB Output is correct
68 Correct 1253 ms 13324 KB Output is correct
69 Correct 572 ms 13336 KB Output is correct
70 Correct 585 ms 13348 KB Output is correct
71 Correct 581 ms 13348 KB Output is correct
72 Correct 609 ms 13372 KB Output is correct
73 Correct 607 ms 13392 KB Output is correct
74 Correct 317 ms 13392 KB Output is correct
75 Correct 291 ms 13392 KB Output is correct
76 Correct 316 ms 13392 KB Output is correct
77 Correct 308 ms 13392 KB Output is correct
78 Correct 329 ms 13392 KB Output is correct