답안 #588728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588728 2022-07-04T00:53:20 Z chonka Boat (APIO16_boat) C++17
9 / 100
7 ms 4368 KB
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int MAXN = 1007 ;
const int MOD = 1e9 + 7 ;
// mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int n ;
pair < int , int > a[ MAXN ] ;
vector < int > v ;

ll dp[ MAXN ][ MAXN ] ;
ll inv[ MAXN ] ;

ll fastpow ( ll x , ll pw ) {
    ll ret = 1 ;
    while ( pw > 0 ) {
        if ( ( pw % 2 ) == 0 ) {
            x = ( x * x ) % MOD ;
            pw /= 2 ;
        }
        else {
            ret = ( ret * x ) % MOD ;
            -- pw ;
        }
    }
    return ret ;
}
set < int > s ;

void solve ( ) {
    cin >> n ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> a[ i ].first >> a[ i ].second ;
        s.insert ( a[ i ].first ) ;
        s.insert ( a[ i ].second + 1 ) ;
    }
    for ( auto x : s ) {
        v.push_back ( x ) ;
    }
    for ( int i = 1 ; i < MAXN ; ++ i ) {
        inv[ i ] = fastpow ( i , MOD - 2 ) ;
    }
    int k = v.size ( ) ;
    dp[ 0 ][ 0 ] = 1 ;
    for ( int i = 0 ; i <= n ; ++ i ) {
        ll up_to = 0 ;
        for ( int j = 0 ; j <= k ; ++ j ) {
            up_to = ( up_to + dp[ i ][ j ] ) % MOD ;
            ll coef = 1 ;
            int cnt = 0 ;
            for ( int t = i + 1 ; t <= n ; ++ t ) {
                if ( !( a[ t ].first <= v[ j ] && v[ j + 1 ] <= a[ t ].second + 1 ) ) { break ; }
                coef = ( coef * ( v[ j + 1 ] - v[ j ] - cnt ) ) % MOD ;
                if ( v[ j + 1 ] - v[ j ] - cnt <= 0 ) { break ; }
                ++ cnt ;
                coef = ( coef * inv[ cnt ] ) % MOD ;
                dp[ t ][ j + 1 ] = ( dp[ t ][ j + 1 ] + up_to * coef ) % MOD ;
            }
            dp[ i + 1 ][ j ] = ( dp[ i + 1 ][ j ] + dp[ i ][ j ] ) % MOD ;
            // dp[ i ][ j + 1 ] = ( dp[ i ][ j + 1 ] + dp[ i ][ j ] ) % MOD ;
        }
        if ( i == n ) {
            cout << ( up_to - 1 + MOD ) % MOD << "\n" ;
        }
    }
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ; // cin >> t ; 
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4308 KB Output is correct
2 Correct 6 ms 4308 KB Output is correct
3 Correct 7 ms 4308 KB Output is correct
4 Correct 6 ms 4308 KB Output is correct
5 Correct 6 ms 4312 KB Output is correct
6 Correct 6 ms 4360 KB Output is correct
7 Correct 7 ms 4368 KB Output is correct
8 Correct 6 ms 4308 KB Output is correct
9 Correct 5 ms 4316 KB Output is correct
10 Correct 5 ms 4308 KB Output is correct
11 Correct 5 ms 4300 KB Output is correct
12 Correct 5 ms 4308 KB Output is correct
13 Correct 5 ms 4312 KB Output is correct
14 Correct 5 ms 4308 KB Output is correct
15 Correct 5 ms 4308 KB Output is correct
16 Correct 3 ms 3028 KB Output is correct
17 Correct 3 ms 3028 KB Output is correct
18 Correct 3 ms 3028 KB Output is correct
19 Correct 3 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4308 KB Output is correct
2 Correct 6 ms 4308 KB Output is correct
3 Correct 7 ms 4308 KB Output is correct
4 Correct 6 ms 4308 KB Output is correct
5 Correct 6 ms 4312 KB Output is correct
6 Correct 6 ms 4360 KB Output is correct
7 Correct 7 ms 4368 KB Output is correct
8 Correct 6 ms 4308 KB Output is correct
9 Correct 5 ms 4316 KB Output is correct
10 Correct 5 ms 4308 KB Output is correct
11 Correct 5 ms 4300 KB Output is correct
12 Correct 5 ms 4308 KB Output is correct
13 Correct 5 ms 4312 KB Output is correct
14 Correct 5 ms 4308 KB Output is correct
15 Correct 5 ms 4308 KB Output is correct
16 Correct 3 ms 3028 KB Output is correct
17 Correct 3 ms 3028 KB Output is correct
18 Correct 3 ms 3028 KB Output is correct
19 Correct 3 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Incorrect 7 ms 4308 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4308 KB Output is correct
2 Correct 6 ms 4308 KB Output is correct
3 Correct 7 ms 4308 KB Output is correct
4 Correct 6 ms 4308 KB Output is correct
5 Correct 6 ms 4312 KB Output is correct
6 Correct 6 ms 4360 KB Output is correct
7 Correct 7 ms 4368 KB Output is correct
8 Correct 6 ms 4308 KB Output is correct
9 Correct 5 ms 4316 KB Output is correct
10 Correct 5 ms 4308 KB Output is correct
11 Correct 5 ms 4300 KB Output is correct
12 Correct 5 ms 4308 KB Output is correct
13 Correct 5 ms 4312 KB Output is correct
14 Correct 5 ms 4308 KB Output is correct
15 Correct 5 ms 4308 KB Output is correct
16 Correct 3 ms 3028 KB Output is correct
17 Correct 3 ms 3028 KB Output is correct
18 Correct 3 ms 3028 KB Output is correct
19 Correct 3 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Incorrect 7 ms 4308 KB Output isn't correct
22 Halted 0 ms 0 KB -