답안 #738892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
738892 2023-05-09T15:25:43 Z Jarif_Rahman Boat (APIO16_boat) C++17
100 / 100
1375 ms 18240 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

const ll md = 1e9+7;
ll pw(ll x, ll p){
    if(!p) return 1;
    if(p&1) return (pw(x, p-1)*x)%md;
    return pw((x*x)%md, p>>1);
}

const int N = 500;
ll fac[N+5], facinv[N+5];
ll combiA[N+5][N+5], combiB[2*N+1][N+5];
ll dp[N][2*N+1], dp_sum[N][2*N+1], C[2*N+1][N+1];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    fac[0] = 1, facinv[0] = 1;
    for(int i = 1; i < N+5; i++) fac[i] = (fac[i-1]*i)%md, facinv[i] = (facinv[i-1]*pw(i, md-2))%md;

    int n; cin >> n;
    vector<int> L(n), R(n);
    vector<int> ranges, _ranges;
    for(int i = 0; i < n; i++) cin >> L[i] >> R[i], _ranges.pb(L[i]), _ranges.pb(R[i]+1);
    sort(_ranges.begin(), _ranges.end());
    for(int x: _ranges)
        if(ranges.empty() || ranges.back() != x) ranges.pb(x);
    int m = int(ranges.size())-1;

    for(int i = 0; i <= n; i++) for(int j = 0; j <= i; j++){
        combiA[i][j] = facinv[j];
        for(int k = i-j+1; k <= i; k++) combiA[i][j]*=k, combiA[i][j]%=md;
    }
    for(int i = 0; i < m; i++){
        int x = ranges[i+1]-ranges[i];
        for(int j = 0; j <= n+1; j++){
            if(j > x){
                combiB[i][j] = 0;
                continue;
            }
            combiB[i][j] = facinv[j];
            for(int k = x-j+1; k <= x; k++) combiB[i][j]*=k, combiB[i][j]%=md;
        }
    }

    for(int i = 0; i < m; i++){
        for(int j = 0; j <= n; j++){
            C[i][j] = 0;
            for(int k = 0; k <= j; k++)
                C[i][j]+=(combiA[j][k]*combiB[i][k+1])%md;
                C[i][j]%=md;
        }
    }

    auto nested = [&](int j, int i){
        return ranges[j] >= L[i] && ranges[j+1]-1 <= R[i];
    };

    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) dp[i][j] = 0, dp_sum[i][j] = 0;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(!nested(j, i)) continue;
            int c = 0;
            for(int k = i; k >= 0; k--){
                if(!nested(j, k)) c++;
                if(j == 0 && k) continue;
                dp[i][j]+=(C[j][i-k-c]*(k ? dp_sum[k-1][j-1]:1))%md;
                dp[i][j]%=md;
            }
        }
        for(int j = 0; j < m; j++){
            if(j) dp_sum[i][j] = dp_sum[i][j-1];
            dp_sum[i][j]+=dp[i][j];
            dp_sum[i][j]%=md;
        }
    }

    ll ans = 0;
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) ans+=dp[i][j], ans%=md;
    cout << ans << "\n";
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:56:13: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   56 |             for(int k = 0; k <= j; k++)
      |             ^~~
boat.cpp:58:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   58 |                 C[i][j]%=md;
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 593 ms 18156 KB Output is correct
2 Correct 598 ms 18044 KB Output is correct
3 Correct 631 ms 18008 KB Output is correct
4 Correct 586 ms 17952 KB Output is correct
5 Correct 582 ms 17996 KB Output is correct
6 Correct 603 ms 17956 KB Output is correct
7 Correct 595 ms 17980 KB Output is correct
8 Correct 587 ms 18012 KB Output is correct
9 Correct 595 ms 18012 KB Output is correct
10 Correct 626 ms 17968 KB Output is correct
11 Correct 626 ms 17912 KB Output is correct
12 Correct 597 ms 18112 KB Output is correct
13 Correct 585 ms 17932 KB Output is correct
14 Correct 597 ms 17912 KB Output is correct
15 Correct 617 ms 17988 KB Output is correct
16 Correct 184 ms 9036 KB Output is correct
17 Correct 195 ms 9292 KB Output is correct
18 Correct 197 ms 9136 KB Output is correct
19 Correct 198 ms 9316 KB Output is correct
20 Correct 191 ms 9160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 593 ms 18156 KB Output is correct
2 Correct 598 ms 18044 KB Output is correct
3 Correct 631 ms 18008 KB Output is correct
4 Correct 586 ms 17952 KB Output is correct
5 Correct 582 ms 17996 KB Output is correct
6 Correct 603 ms 17956 KB Output is correct
7 Correct 595 ms 17980 KB Output is correct
8 Correct 587 ms 18012 KB Output is correct
9 Correct 595 ms 18012 KB Output is correct
10 Correct 626 ms 17968 KB Output is correct
11 Correct 626 ms 17912 KB Output is correct
12 Correct 597 ms 18112 KB Output is correct
13 Correct 585 ms 17932 KB Output is correct
14 Correct 597 ms 17912 KB Output is correct
15 Correct 617 ms 17988 KB Output is correct
16 Correct 184 ms 9036 KB Output is correct
17 Correct 195 ms 9292 KB Output is correct
18 Correct 197 ms 9136 KB Output is correct
19 Correct 198 ms 9316 KB Output is correct
20 Correct 191 ms 9160 KB Output is correct
21 Correct 586 ms 17400 KB Output is correct
22 Correct 623 ms 17432 KB Output is correct
23 Correct 555 ms 17268 KB Output is correct
24 Correct 528 ms 17176 KB Output is correct
25 Correct 530 ms 17356 KB Output is correct
26 Correct 654 ms 16972 KB Output is correct
27 Correct 697 ms 17196 KB Output is correct
28 Correct 658 ms 17068 KB Output is correct
29 Correct 650 ms 17044 KB Output is correct
30 Correct 565 ms 17984 KB Output is correct
31 Correct 583 ms 18016 KB Output is correct
32 Correct 564 ms 17996 KB Output is correct
33 Correct 590 ms 17996 KB Output is correct
34 Correct 582 ms 17876 KB Output is correct
35 Correct 559 ms 17948 KB Output is correct
36 Correct 564 ms 17996 KB Output is correct
37 Correct 584 ms 18076 KB Output is correct
38 Correct 572 ms 17976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 3412 KB Output is correct
2 Correct 11 ms 3412 KB Output is correct
3 Correct 11 ms 3412 KB Output is correct
4 Correct 11 ms 3412 KB Output is correct
5 Correct 11 ms 3404 KB Output is correct
6 Correct 12 ms 3408 KB Output is correct
7 Correct 13 ms 3404 KB Output is correct
8 Correct 12 ms 3320 KB Output is correct
9 Correct 12 ms 3412 KB Output is correct
10 Correct 12 ms 3412 KB Output is correct
11 Correct 11 ms 3448 KB Output is correct
12 Correct 11 ms 3448 KB Output is correct
13 Correct 11 ms 3412 KB Output is correct
14 Correct 11 ms 3408 KB Output is correct
15 Correct 12 ms 3480 KB Output is correct
16 Correct 7 ms 2644 KB Output is correct
17 Correct 6 ms 2516 KB Output is correct
18 Correct 7 ms 2516 KB Output is correct
19 Correct 7 ms 2516 KB Output is correct
20 Correct 7 ms 2516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 593 ms 18156 KB Output is correct
2 Correct 598 ms 18044 KB Output is correct
3 Correct 631 ms 18008 KB Output is correct
4 Correct 586 ms 17952 KB Output is correct
5 Correct 582 ms 17996 KB Output is correct
6 Correct 603 ms 17956 KB Output is correct
7 Correct 595 ms 17980 KB Output is correct
8 Correct 587 ms 18012 KB Output is correct
9 Correct 595 ms 18012 KB Output is correct
10 Correct 626 ms 17968 KB Output is correct
11 Correct 626 ms 17912 KB Output is correct
12 Correct 597 ms 18112 KB Output is correct
13 Correct 585 ms 17932 KB Output is correct
14 Correct 597 ms 17912 KB Output is correct
15 Correct 617 ms 17988 KB Output is correct
16 Correct 184 ms 9036 KB Output is correct
17 Correct 195 ms 9292 KB Output is correct
18 Correct 197 ms 9136 KB Output is correct
19 Correct 198 ms 9316 KB Output is correct
20 Correct 191 ms 9160 KB Output is correct
21 Correct 586 ms 17400 KB Output is correct
22 Correct 623 ms 17432 KB Output is correct
23 Correct 555 ms 17268 KB Output is correct
24 Correct 528 ms 17176 KB Output is correct
25 Correct 530 ms 17356 KB Output is correct
26 Correct 654 ms 16972 KB Output is correct
27 Correct 697 ms 17196 KB Output is correct
28 Correct 658 ms 17068 KB Output is correct
29 Correct 650 ms 17044 KB Output is correct
30 Correct 565 ms 17984 KB Output is correct
31 Correct 583 ms 18016 KB Output is correct
32 Correct 564 ms 17996 KB Output is correct
33 Correct 590 ms 17996 KB Output is correct
34 Correct 582 ms 17876 KB Output is correct
35 Correct 559 ms 17948 KB Output is correct
36 Correct 564 ms 17996 KB Output is correct
37 Correct 584 ms 18076 KB Output is correct
38 Correct 572 ms 17976 KB Output is correct
39 Correct 11 ms 3412 KB Output is correct
40 Correct 11 ms 3412 KB Output is correct
41 Correct 11 ms 3412 KB Output is correct
42 Correct 11 ms 3412 KB Output is correct
43 Correct 11 ms 3404 KB Output is correct
44 Correct 12 ms 3408 KB Output is correct
45 Correct 13 ms 3404 KB Output is correct
46 Correct 12 ms 3320 KB Output is correct
47 Correct 12 ms 3412 KB Output is correct
48 Correct 12 ms 3412 KB Output is correct
49 Correct 11 ms 3448 KB Output is correct
50 Correct 11 ms 3448 KB Output is correct
51 Correct 11 ms 3412 KB Output is correct
52 Correct 11 ms 3408 KB Output is correct
53 Correct 12 ms 3480 KB Output is correct
54 Correct 7 ms 2644 KB Output is correct
55 Correct 6 ms 2516 KB Output is correct
56 Correct 7 ms 2516 KB Output is correct
57 Correct 7 ms 2516 KB Output is correct
58 Correct 7 ms 2516 KB Output is correct
59 Correct 1211 ms 18104 KB Output is correct
60 Correct 1176 ms 18128 KB Output is correct
61 Correct 1145 ms 17972 KB Output is correct
62 Correct 1222 ms 18240 KB Output is correct
63 Correct 1145 ms 18104 KB Output is correct
64 Correct 1288 ms 18032 KB Output is correct
65 Correct 1274 ms 18036 KB Output is correct
66 Correct 1345 ms 18072 KB Output is correct
67 Correct 1375 ms 18032 KB Output is correct
68 Correct 1282 ms 18124 KB Output is correct
69 Correct 1130 ms 18128 KB Output is correct
70 Correct 1098 ms 18036 KB Output is correct
71 Correct 1090 ms 18028 KB Output is correct
72 Correct 1074 ms 18124 KB Output is correct
73 Correct 1097 ms 18144 KB Output is correct
74 Correct 266 ms 9164 KB Output is correct
75 Correct 263 ms 9164 KB Output is correct
76 Correct 262 ms 9172 KB Output is correct
77 Correct 259 ms 9192 KB Output is correct
78 Correct 254 ms 9144 KB Output is correct