Submission #48048

# Submission time Handle Problem Language Result Execution time Memory
48048 2018-05-09T15:13:23 Z shirowa Boat (APIO16_boat) C++14
0 / 100
33 ms 12664 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;
    }
    dd[0]=1;
    for(int i=0;i<n;i++){
        dd[i+1]=a[i];
        dd[i+1+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[n][m-1]=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];
        c[i][0]=1;
        for(int j=1;j<505;j++){
            if(i<j)c[i][j]=0;
            if(i>=j){
                c[i][j]=s*inv[j]%p;
                t=(ll[i]-j)*s%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]&&i!=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;
        }
    }
    printf("%lld\n",sum[n-1][m-1]-1);
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:101: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]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 12664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 12664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 12664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 12664 KB Output isn't correct
2 Halted 0 ms 0 KB -