답안 #208189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208189 2020-03-10T08:27:11 Z DodgeBallMan Boat (APIO16_boat) C++14
0 / 100
10 ms 4472 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 5e2 + 10;
const long long mod = 1e9 + 7;
int n;
long long dp[N][2*N], a[N], b[N];
vector<long long> coord;
long long solve( int pos, long long mi ) {
    if( pos > n ){
        if( mi == 0 ) return 0;
        else return coord[mi] - coord[mi-1];
    }
    //printf("%d %lld\n",pos,mi);
    long long &ret = dp[pos][mi];
    if( ret != -1 ) return ret; 
    ret = 0;
    ret = ( ret + solve( pos+1, mi ) ) % mod;
    if( mi < a[pos] ) ret = ( ret + solve( pos+1, a[pos] ) ) % mod;
    for( int i = max( a[pos] + 1, mi + 1 ) ; i <= b[pos] ; i++ ) ret = ( ret + ( coord[i] - coord[i-1] ) * solve( pos+1, i ) ) % mod;
    //printf("%lld\n",ret);
    return ret % mod;
}

int main()
{
    memset( dp, -1, sizeof dp );
    scanf("%d",&n);
    coord.emplace_back( 0LL );
    for( int i = 1 ; i <= n ; i++ ) {
        scanf("%lld %lld",&a[i],&b[i]);
        coord.emplace_back( a[i] ), coord.emplace_back( b[i] );
    }
    sort( coord.begin(), coord.end() );
    coord.resize( unique(coord.begin(), coord.end() ) - coord.begin());
    for( int i = 1 ; i <= n ; i++ ) {
        a[i] = lower_bound( coord.begin(), coord.end(), a[i] ) - coord.begin();
        b[i] = lower_bound( coord.begin(), coord.end(), b[i] ) - coord.begin(); 
    }
    printf("%lld",solve( 1, 0LL ));
    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
boat.cpp:32: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 Incorrect 10 ms 4472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 4472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 4472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 4472 KB Output isn't correct
2 Halted 0 ms 0 KB -