답안 #589538

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

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

ll dp[ MAXN ][ 2 * 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 ) ;
    }
    int k = 0 ;
    for ( auto x : s ) {
        v[ ++ k ] = x ;
    }
    -- k ;
    for ( int i = 1 ; i < MAXN ; ++ i ) {
        inv[ i ] = fastpow ( i , MOD - 2 ) ;
    }
    for ( int i = 0 ; i <= k ; ++ i ) {
        dp[ 0 ][ i ] = 1 ;
    }
    for ( int i = 1 ; i <= n ; ++ i ) {
        dp[ i ][ 0 ] = 1 ;
        for ( int j = 1 ; j <= k ; ++ j ) {
            dp[ i ][ j ] = dp[ i ][ j - 1 ] ;
            ll coef = 1 ;
            int cnt = 0 ;
            for ( int t = i ; t >= 1 ; -- t ) {
                if ( a[ t ].first <= v[ j ] && v[ j + 1 ] <= a[ t ].second + 1 ) {
                    coef = ( coef * ( v[ j + 1 ] - v[ j ] + cnt ) ) % MOD ;
                    coef = ( coef * inv[ cnt + 1 ] ) % MOD ;
                    ++ cnt ;
                    dp[ i ][ j ] = ( dp[ i ][ j ] + coef * dp[ t - 1 ][ j - 1 ] ) % MOD ;
                }
            }
        }
    }
    cout << ( dp[ n ][ k ] - 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 268 ms 4300 KB Output is correct
2 Correct 265 ms 4212 KB Output is correct
3 Correct 273 ms 4212 KB Output is correct
4 Correct 293 ms 4232 KB Output is correct
5 Correct 255 ms 4304 KB Output is correct
6 Correct 171 ms 4248 KB Output is correct
7 Correct 194 ms 4244 KB Output is correct
8 Correct 174 ms 4240 KB Output is correct
9 Correct 183 ms 4332 KB Output is correct
10 Correct 170 ms 4284 KB Output is correct
11 Correct 170 ms 4300 KB Output is correct
12 Correct 170 ms 4208 KB Output is correct
13 Correct 192 ms 4236 KB Output is correct
14 Correct 158 ms 4272 KB Output is correct
15 Correct 164 ms 4300 KB Output is correct
16 Correct 55 ms 3020 KB Output is correct
17 Correct 55 ms 2988 KB Output is correct
18 Correct 56 ms 2976 KB Output is correct
19 Correct 69 ms 3080 KB Output is correct
20 Correct 56 ms 3020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 268 ms 4300 KB Output is correct
2 Correct 265 ms 4212 KB Output is correct
3 Correct 273 ms 4212 KB Output is correct
4 Correct 293 ms 4232 KB Output is correct
5 Correct 255 ms 4304 KB Output is correct
6 Correct 171 ms 4248 KB Output is correct
7 Correct 194 ms 4244 KB Output is correct
8 Correct 174 ms 4240 KB Output is correct
9 Correct 183 ms 4332 KB Output is correct
10 Correct 170 ms 4284 KB Output is correct
11 Correct 170 ms 4300 KB Output is correct
12 Correct 170 ms 4208 KB Output is correct
13 Correct 192 ms 4236 KB Output is correct
14 Correct 158 ms 4272 KB Output is correct
15 Correct 164 ms 4300 KB Output is correct
16 Correct 55 ms 3020 KB Output is correct
17 Correct 55 ms 2988 KB Output is correct
18 Correct 56 ms 2976 KB Output is correct
19 Correct 69 ms 3080 KB Output is correct
20 Correct 56 ms 3020 KB Output is correct
21 Correct 454 ms 4416 KB Output is correct
22 Correct 447 ms 4256 KB Output is correct
23 Correct 420 ms 4324 KB Output is correct
24 Correct 449 ms 4304 KB Output is correct
25 Correct 466 ms 4252 KB Output is correct
26 Correct 634 ms 4348 KB Output is correct
27 Correct 668 ms 4340 KB Output is correct
28 Correct 641 ms 4348 KB Output is correct
29 Correct 638 ms 4228 KB Output is correct
30 Correct 179 ms 4296 KB Output is correct
31 Correct 165 ms 4288 KB Output is correct
32 Correct 184 ms 4368 KB Output is correct
33 Correct 170 ms 4244 KB Output is correct
34 Correct 165 ms 4272 KB Output is correct
35 Correct 283 ms 4196 KB Output is correct
36 Correct 296 ms 4208 KB Output is correct
37 Correct 280 ms 4240 KB Output is correct
38 Correct 316 ms 4264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 852 KB Output is correct
2 Correct 5 ms 892 KB Output is correct
3 Correct 4 ms 852 KB Output is correct
4 Correct 4 ms 852 KB Output is correct
5 Correct 4 ms 852 KB Output is correct
6 Correct 6 ms 840 KB Output is correct
7 Correct 6 ms 880 KB Output is correct
8 Correct 7 ms 832 KB Output is correct
9 Correct 7 ms 852 KB Output is correct
10 Correct 6 ms 848 KB Output is correct
11 Correct 6 ms 980 KB Output is correct
12 Correct 5 ms 852 KB Output is correct
13 Correct 5 ms 892 KB Output is correct
14 Correct 5 ms 852 KB Output is correct
15 Correct 6 ms 876 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 268 ms 4300 KB Output is correct
2 Correct 265 ms 4212 KB Output is correct
3 Correct 273 ms 4212 KB Output is correct
4 Correct 293 ms 4232 KB Output is correct
5 Correct 255 ms 4304 KB Output is correct
6 Correct 171 ms 4248 KB Output is correct
7 Correct 194 ms 4244 KB Output is correct
8 Correct 174 ms 4240 KB Output is correct
9 Correct 183 ms 4332 KB Output is correct
10 Correct 170 ms 4284 KB Output is correct
11 Correct 170 ms 4300 KB Output is correct
12 Correct 170 ms 4208 KB Output is correct
13 Correct 192 ms 4236 KB Output is correct
14 Correct 158 ms 4272 KB Output is correct
15 Correct 164 ms 4300 KB Output is correct
16 Correct 55 ms 3020 KB Output is correct
17 Correct 55 ms 2988 KB Output is correct
18 Correct 56 ms 2976 KB Output is correct
19 Correct 69 ms 3080 KB Output is correct
20 Correct 56 ms 3020 KB Output is correct
21 Correct 454 ms 4416 KB Output is correct
22 Correct 447 ms 4256 KB Output is correct
23 Correct 420 ms 4324 KB Output is correct
24 Correct 449 ms 4304 KB Output is correct
25 Correct 466 ms 4252 KB Output is correct
26 Correct 634 ms 4348 KB Output is correct
27 Correct 668 ms 4340 KB Output is correct
28 Correct 641 ms 4348 KB Output is correct
29 Correct 638 ms 4228 KB Output is correct
30 Correct 179 ms 4296 KB Output is correct
31 Correct 165 ms 4288 KB Output is correct
32 Correct 184 ms 4368 KB Output is correct
33 Correct 170 ms 4244 KB Output is correct
34 Correct 165 ms 4272 KB Output is correct
35 Correct 283 ms 4196 KB Output is correct
36 Correct 296 ms 4208 KB Output is correct
37 Correct 280 ms 4240 KB Output is correct
38 Correct 316 ms 4264 KB Output is correct
39 Correct 5 ms 852 KB Output is correct
40 Correct 5 ms 892 KB Output is correct
41 Correct 4 ms 852 KB Output is correct
42 Correct 4 ms 852 KB Output is correct
43 Correct 4 ms 852 KB Output is correct
44 Correct 6 ms 840 KB Output is correct
45 Correct 6 ms 880 KB Output is correct
46 Correct 7 ms 832 KB Output is correct
47 Correct 7 ms 852 KB Output is correct
48 Correct 6 ms 848 KB Output is correct
49 Correct 6 ms 980 KB Output is correct
50 Correct 5 ms 852 KB Output is correct
51 Correct 5 ms 892 KB Output is correct
52 Correct 5 ms 852 KB Output is correct
53 Correct 6 ms 876 KB Output is correct
54 Correct 3 ms 724 KB Output is correct
55 Correct 3 ms 724 KB Output is correct
56 Correct 4 ms 724 KB Output is correct
57 Correct 3 ms 724 KB Output is correct
58 Correct 3 ms 724 KB Output is correct
59 Correct 497 ms 4404 KB Output is correct
60 Correct 487 ms 4236 KB Output is correct
61 Correct 469 ms 4456 KB Output is correct
62 Correct 490 ms 4272 KB Output is correct
63 Correct 497 ms 4208 KB Output is correct
64 Correct 729 ms 4296 KB Output is correct
65 Correct 712 ms 4416 KB Output is correct
66 Correct 710 ms 4252 KB Output is correct
67 Correct 709 ms 4200 KB Output is correct
68 Correct 705 ms 4296 KB Output is correct
69 Correct 527 ms 4244 KB Output is correct
70 Correct 573 ms 4344 KB Output is correct
71 Correct 545 ms 4292 KB Output is correct
72 Correct 563 ms 4312 KB Output is correct
73 Correct 549 ms 4240 KB Output is correct
74 Correct 99 ms 2936 KB Output is correct
75 Correct 102 ms 3056 KB Output is correct
76 Correct 101 ms 3008 KB Output is correct
77 Correct 100 ms 3044 KB Output is correct
78 Correct 103 ms 3020 KB Output is correct