답안 #48062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48062 2018-05-09T17:57:35 Z shirowa Boat (APIO16_boat) C++14
36 / 100
526 ms 12860 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 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++){
            if(ll[i]<j)c[i][j]=0;
            if(ll[i]>=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:33:15: warning: variable 'com' set but not used [-Wunused-but-set-variable]
     long long com[505][505];
               ^~~
boat.cpp:112: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 29 ms 12664 KB Output is correct
2 Correct 30 ms 12664 KB Output is correct
3 Correct 29 ms 12724 KB Output is correct
4 Correct 29 ms 12744 KB Output is correct
5 Correct 29 ms 12744 KB Output is correct
6 Correct 29 ms 12860 KB Output is correct
7 Correct 29 ms 12860 KB Output is correct
8 Correct 29 ms 12860 KB Output is correct
9 Correct 29 ms 12860 KB Output is correct
10 Correct 29 ms 12860 KB Output is correct
11 Correct 31 ms 12860 KB Output is correct
12 Correct 29 ms 12860 KB Output is correct
13 Correct 30 ms 12860 KB Output is correct
14 Correct 29 ms 12860 KB Output is correct
15 Correct 29 ms 12860 KB Output is correct
16 Correct 17 ms 12860 KB Output is correct
17 Correct 17 ms 12860 KB Output is correct
18 Correct 16 ms 12860 KB Output is correct
19 Correct 16 ms 12860 KB Output is correct
20 Correct 16 ms 12860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 12664 KB Output is correct
2 Correct 30 ms 12664 KB Output is correct
3 Correct 29 ms 12724 KB Output is correct
4 Correct 29 ms 12744 KB Output is correct
5 Correct 29 ms 12744 KB Output is correct
6 Correct 29 ms 12860 KB Output is correct
7 Correct 29 ms 12860 KB Output is correct
8 Correct 29 ms 12860 KB Output is correct
9 Correct 29 ms 12860 KB Output is correct
10 Correct 29 ms 12860 KB Output is correct
11 Correct 31 ms 12860 KB Output is correct
12 Correct 29 ms 12860 KB Output is correct
13 Correct 30 ms 12860 KB Output is correct
14 Correct 29 ms 12860 KB Output is correct
15 Correct 29 ms 12860 KB Output is correct
16 Correct 17 ms 12860 KB Output is correct
17 Correct 17 ms 12860 KB Output is correct
18 Correct 16 ms 12860 KB Output is correct
19 Correct 16 ms 12860 KB Output is correct
20 Correct 16 ms 12860 KB Output is correct
21 Incorrect 526 ms 12860 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12860 KB Output is correct
2 Correct 9 ms 12860 KB Output is correct
3 Correct 11 ms 12860 KB Output is correct
4 Correct 11 ms 12860 KB Output is correct
5 Correct 11 ms 12860 KB Output is correct
6 Correct 15 ms 12860 KB Output is correct
7 Correct 15 ms 12860 KB Output is correct
8 Correct 15 ms 12860 KB Output is correct
9 Correct 15 ms 12860 KB Output is correct
10 Correct 15 ms 12860 KB Output is correct
11 Correct 11 ms 12860 KB Output is correct
12 Correct 11 ms 12860 KB Output is correct
13 Correct 10 ms 12860 KB Output is correct
14 Correct 10 ms 12860 KB Output is correct
15 Correct 11 ms 12860 KB Output is correct
16 Correct 8 ms 12860 KB Output is correct
17 Correct 7 ms 12860 KB Output is correct
18 Correct 8 ms 12860 KB Output is correct
19 Correct 7 ms 12860 KB Output is correct
20 Correct 8 ms 12860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 12664 KB Output is correct
2 Correct 30 ms 12664 KB Output is correct
3 Correct 29 ms 12724 KB Output is correct
4 Correct 29 ms 12744 KB Output is correct
5 Correct 29 ms 12744 KB Output is correct
6 Correct 29 ms 12860 KB Output is correct
7 Correct 29 ms 12860 KB Output is correct
8 Correct 29 ms 12860 KB Output is correct
9 Correct 29 ms 12860 KB Output is correct
10 Correct 29 ms 12860 KB Output is correct
11 Correct 31 ms 12860 KB Output is correct
12 Correct 29 ms 12860 KB Output is correct
13 Correct 30 ms 12860 KB Output is correct
14 Correct 29 ms 12860 KB Output is correct
15 Correct 29 ms 12860 KB Output is correct
16 Correct 17 ms 12860 KB Output is correct
17 Correct 17 ms 12860 KB Output is correct
18 Correct 16 ms 12860 KB Output is correct
19 Correct 16 ms 12860 KB Output is correct
20 Correct 16 ms 12860 KB Output is correct
21 Incorrect 526 ms 12860 KB Output isn't correct
22 Halted 0 ms 0 KB -