답안 #48059

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48059 2018-05-09T17:38:39 Z shirowa Boat (APIO16_boat) C++14
9 / 100
2000 ms 19048 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 k;
    long long com[505][505];
    for(int i=0;i<505;i++){
        for(int j=0;j<505;j++){
            if(i<j)com[i][j]=0;
            if(i>=j){
                k=kai[i]*inv[i-j]%p;
                com[i][j]=k*inv[j]%p;
            }
        }
    }
    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 co[m-1][505];
    long long s,t;
    for(int i=0;i<m-1;i++){
        s=ll[i];
        co[i][0]=1;
        for(int j=1;j<505;j++){
            if(ll[i]<j)co[i][j]=0;
            if(ll[i]>=j){
                co[i][j]=s*inv[j]%p;
                t=(ll[i]-j)*s%p;
                s=t;
            }
        }
    }
    long long c[m-1][505];
    for(int i=0;i<m-1;i++){
        for(int j=0;j<3;j++){
            c[i][j]=co[i][j];
        }
        for(int j=3;j<505;j++){
            c[i][j]=0;
            for(int h=0;h<=j-2;h++){
                c[i][j]+=(co[i][j]*com[j-2][h])%p;
                if(c[i][j]>=p)c[i][j]-=p;
            }
        }
    }
    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:124: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 1699 ms 18664 KB Output is correct
2 Correct 1663 ms 18760 KB Output is correct
3 Correct 1708 ms 18760 KB Output is correct
4 Correct 1681 ms 18864 KB Output is correct
5 Correct 1670 ms 18864 KB Output is correct
6 Correct 1699 ms 18864 KB Output is correct
7 Correct 1695 ms 18864 KB Output is correct
8 Correct 1683 ms 18900 KB Output is correct
9 Correct 1699 ms 18900 KB Output is correct
10 Correct 1697 ms 18900 KB Output is correct
11 Correct 1678 ms 19048 KB Output is correct
12 Correct 1685 ms 19048 KB Output is correct
13 Correct 1717 ms 19048 KB Output is correct
14 Correct 1677 ms 19048 KB Output is correct
15 Correct 1691 ms 19048 KB Output is correct
16 Correct 904 ms 19048 KB Output is correct
17 Correct 916 ms 19048 KB Output is correct
18 Correct 921 ms 19048 KB Output is correct
19 Correct 924 ms 19048 KB Output is correct
20 Correct 901 ms 19048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1699 ms 18664 KB Output is correct
2 Correct 1663 ms 18760 KB Output is correct
3 Correct 1708 ms 18760 KB Output is correct
4 Correct 1681 ms 18864 KB Output is correct
5 Correct 1670 ms 18864 KB Output is correct
6 Correct 1699 ms 18864 KB Output is correct
7 Correct 1695 ms 18864 KB Output is correct
8 Correct 1683 ms 18900 KB Output is correct
9 Correct 1699 ms 18900 KB Output is correct
10 Correct 1697 ms 18900 KB Output is correct
11 Correct 1678 ms 19048 KB Output is correct
12 Correct 1685 ms 19048 KB Output is correct
13 Correct 1717 ms 19048 KB Output is correct
14 Correct 1677 ms 19048 KB Output is correct
15 Correct 1691 ms 19048 KB Output is correct
16 Correct 904 ms 19048 KB Output is correct
17 Correct 916 ms 19048 KB Output is correct
18 Correct 921 ms 19048 KB Output is correct
19 Correct 924 ms 19048 KB Output is correct
20 Correct 901 ms 19048 KB Output is correct
21 Execution timed out 2017 ms 19048 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 352 ms 19048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1699 ms 18664 KB Output is correct
2 Correct 1663 ms 18760 KB Output is correct
3 Correct 1708 ms 18760 KB Output is correct
4 Correct 1681 ms 18864 KB Output is correct
5 Correct 1670 ms 18864 KB Output is correct
6 Correct 1699 ms 18864 KB Output is correct
7 Correct 1695 ms 18864 KB Output is correct
8 Correct 1683 ms 18900 KB Output is correct
9 Correct 1699 ms 18900 KB Output is correct
10 Correct 1697 ms 18900 KB Output is correct
11 Correct 1678 ms 19048 KB Output is correct
12 Correct 1685 ms 19048 KB Output is correct
13 Correct 1717 ms 19048 KB Output is correct
14 Correct 1677 ms 19048 KB Output is correct
15 Correct 1691 ms 19048 KB Output is correct
16 Correct 904 ms 19048 KB Output is correct
17 Correct 916 ms 19048 KB Output is correct
18 Correct 921 ms 19048 KB Output is correct
19 Correct 924 ms 19048 KB Output is correct
20 Correct 901 ms 19048 KB Output is correct
21 Execution timed out 2017 ms 19048 KB Time limit exceeded
22 Halted 0 ms 0 KB -