답안 #681624

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681624 2023-01-13T13:18:39 Z 79brue Boat (APIO16_boat) C++17
100 / 100
908 ms 19972 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll MOD = 1000000007;

ll mpow(ll x, ll y){
    if(!y) return 1;
    if(y%2) return mpow(x, y-1) * x % MOD;
    ll tmp = mpow(x, y/2);
    return tmp * tmp % MOD;
}

ll modInv(ll x){
    return mpow(x, MOD-2);
}

int n, k;
ll a[502], b[502];
ll arr[1002];

void input();
void init();
void solve();
void output();

int main(){
    input();
    init();
    solve();
    output();
}

void input(){
    vector<int> vec;
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%lld %lld", &a[i], &b[i]);
        a[i]--;
        vec.push_back(a[i]);
        vec.push_back(b[i]);
    }
    vec.push_back(0);
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());

    k = (int)vec.size() - 1;
    for(int i=0; i<=k; i++) arr[i] = vec[i];

    for(int i=1; i<=n; i++){
        a[i] = lower_bound(arr, arr+k+1, a[i]) - arr + 1;
        b[i] = lower_bound(arr, arr+k+1, b[i]) - arr;
    }
}

ll nCk[502][502];
ll xCi[1002][502];
ll xySum[1002][502];

void init(){
    /// nCk
    for(int i=0; i<=n; i++){
        nCk[i][0] = nCk[i][i] = 1;
        for(int j=1; j<i; j++){
            nCk[i][j] = (nCk[i-1][j] + nCk[i-1][j-1]) % MOD;
        }
    }

    /// xCi
    for(int i=1; i<=k; i++){
        ll X = arr[i] - arr[i-1];
        xCi[i][1] = X;
        for(int j=2; j<=n; j++){
            xCi[i][j] = xCi[i][j-1] * (X-j+1) % MOD * modInv(j) % MOD;
        }
    }

    /// xyMult
    for(int i=1; i<=k; i++){
        for(int j=1; j<=n; j++){
            for(int d=1; d<=j; d++){
                xySum[i][j] = (xySum[i][j] + xCi[i][d] * nCk[j-1][d-1]) % MOD;
            }
        }
    }
}

int sum[502][1002];
ll DP[502][1002];
ll DPsum[502][1002];

void solve(){
    /// sum
    for(int i=1; i<=n; i++){
        for(int j=a[i]; j<=b[i]; j++){
            sum[i][j] = 1;
        }
    }
    for(int j=1; j<=k; j++) for(int i=1; i<=n; i++) sum[i][j] += sum[i-1][j];

    DP[0][0] = 1;
    for(int i=0; i<=k; i++) DPsum[0][i] = 1;

    for(int i=1; i<=n; i++){
        for(int j=1; j<=k; j++){
            if(j < a[i] || b[i] < j) continue;
            for(int prv=0; prv<i; prv++){
                DP[i][j] = (DP[i][j] + DPsum[prv][j-1] * xySum[j][sum[i][j]-sum[prv][j]]) % MOD;
            }
        }

        for(int j=1; j<=k; j++) DPsum[i][j] = (DPsum[i][j-1] + DP[i][j]) % MOD;

//        for(int j=1; j<=k; j++) printf("%lld ", DP[i][j]);
//        puts("");
    }
}

ll ans;

void output(){
    for(int i=1; i<=n; i++){
        for(int j=1; j<=k; j++){
            ans = (ans + DP[i][j]) % MOD;
        }
    }

    printf("%lld", ans);
}

Compilation message

boat.cpp: In function 'void input()':
boat.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
boat.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         scanf("%lld %lld", &a[i], &b[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 619 ms 17908 KB Output is correct
2 Correct 630 ms 17960 KB Output is correct
3 Correct 623 ms 17852 KB Output is correct
4 Correct 619 ms 17832 KB Output is correct
5 Correct 619 ms 17968 KB Output is correct
6 Correct 622 ms 18104 KB Output is correct
7 Correct 625 ms 18052 KB Output is correct
8 Correct 620 ms 18044 KB Output is correct
9 Correct 618 ms 17988 KB Output is correct
10 Correct 620 ms 18000 KB Output is correct
11 Correct 625 ms 17920 KB Output is correct
12 Correct 623 ms 17920 KB Output is correct
13 Correct 618 ms 18048 KB Output is correct
14 Correct 617 ms 18036 KB Output is correct
15 Correct 622 ms 18112 KB Output is correct
16 Correct 114 ms 10344 KB Output is correct
17 Correct 120 ms 10412 KB Output is correct
18 Correct 124 ms 10384 KB Output is correct
19 Correct 121 ms 10420 KB Output is correct
20 Correct 119 ms 10332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 619 ms 17908 KB Output is correct
2 Correct 630 ms 17960 KB Output is correct
3 Correct 623 ms 17852 KB Output is correct
4 Correct 619 ms 17832 KB Output is correct
5 Correct 619 ms 17968 KB Output is correct
6 Correct 622 ms 18104 KB Output is correct
7 Correct 625 ms 18052 KB Output is correct
8 Correct 620 ms 18044 KB Output is correct
9 Correct 618 ms 17988 KB Output is correct
10 Correct 620 ms 18000 KB Output is correct
11 Correct 625 ms 17920 KB Output is correct
12 Correct 623 ms 17920 KB Output is correct
13 Correct 618 ms 18048 KB Output is correct
14 Correct 617 ms 18036 KB Output is correct
15 Correct 622 ms 18112 KB Output is correct
16 Correct 114 ms 10344 KB Output is correct
17 Correct 120 ms 10412 KB Output is correct
18 Correct 124 ms 10384 KB Output is correct
19 Correct 121 ms 10420 KB Output is correct
20 Correct 119 ms 10332 KB Output is correct
21 Correct 732 ms 18412 KB Output is correct
22 Correct 737 ms 18436 KB Output is correct
23 Correct 747 ms 18248 KB Output is correct
24 Correct 728 ms 18108 KB Output is correct
25 Correct 720 ms 18276 KB Output is correct
26 Correct 772 ms 18772 KB Output is correct
27 Correct 780 ms 18932 KB Output is correct
28 Correct 768 ms 18736 KB Output is correct
29 Correct 775 ms 18648 KB Output is correct
30 Correct 637 ms 18024 KB Output is correct
31 Correct 622 ms 18060 KB Output is correct
32 Correct 647 ms 17956 KB Output is correct
33 Correct 616 ms 17996 KB Output is correct
34 Correct 634 ms 18104 KB Output is correct
35 Correct 624 ms 18072 KB Output is correct
36 Correct 618 ms 17912 KB Output is correct
37 Correct 622 ms 18052 KB Output is correct
38 Correct 621 ms 17872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 3668 KB Output is correct
2 Correct 12 ms 3636 KB Output is correct
3 Correct 12 ms 3668 KB Output is correct
4 Correct 14 ms 3680 KB Output is correct
5 Correct 13 ms 3688 KB Output is correct
6 Correct 15 ms 3668 KB Output is correct
7 Correct 14 ms 3668 KB Output is correct
8 Correct 16 ms 3716 KB Output is correct
9 Correct 13 ms 3668 KB Output is correct
10 Correct 13 ms 3652 KB Output is correct
11 Correct 12 ms 3636 KB Output is correct
12 Correct 12 ms 3632 KB Output is correct
13 Correct 13 ms 3656 KB Output is correct
14 Correct 12 ms 3660 KB Output is correct
15 Correct 12 ms 3668 KB Output is correct
16 Correct 8 ms 2880 KB Output is correct
17 Correct 7 ms 2864 KB Output is correct
18 Correct 8 ms 2900 KB Output is correct
19 Correct 8 ms 2900 KB Output is correct
20 Correct 8 ms 2868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 619 ms 17908 KB Output is correct
2 Correct 630 ms 17960 KB Output is correct
3 Correct 623 ms 17852 KB Output is correct
4 Correct 619 ms 17832 KB Output is correct
5 Correct 619 ms 17968 KB Output is correct
6 Correct 622 ms 18104 KB Output is correct
7 Correct 625 ms 18052 KB Output is correct
8 Correct 620 ms 18044 KB Output is correct
9 Correct 618 ms 17988 KB Output is correct
10 Correct 620 ms 18000 KB Output is correct
11 Correct 625 ms 17920 KB Output is correct
12 Correct 623 ms 17920 KB Output is correct
13 Correct 618 ms 18048 KB Output is correct
14 Correct 617 ms 18036 KB Output is correct
15 Correct 622 ms 18112 KB Output is correct
16 Correct 114 ms 10344 KB Output is correct
17 Correct 120 ms 10412 KB Output is correct
18 Correct 124 ms 10384 KB Output is correct
19 Correct 121 ms 10420 KB Output is correct
20 Correct 119 ms 10332 KB Output is correct
21 Correct 732 ms 18412 KB Output is correct
22 Correct 737 ms 18436 KB Output is correct
23 Correct 747 ms 18248 KB Output is correct
24 Correct 728 ms 18108 KB Output is correct
25 Correct 720 ms 18276 KB Output is correct
26 Correct 772 ms 18772 KB Output is correct
27 Correct 780 ms 18932 KB Output is correct
28 Correct 768 ms 18736 KB Output is correct
29 Correct 775 ms 18648 KB Output is correct
30 Correct 637 ms 18024 KB Output is correct
31 Correct 622 ms 18060 KB Output is correct
32 Correct 647 ms 17956 KB Output is correct
33 Correct 616 ms 17996 KB Output is correct
34 Correct 634 ms 18104 KB Output is correct
35 Correct 624 ms 18072 KB Output is correct
36 Correct 618 ms 17912 KB Output is correct
37 Correct 622 ms 18052 KB Output is correct
38 Correct 621 ms 17872 KB Output is correct
39 Correct 12 ms 3668 KB Output is correct
40 Correct 12 ms 3636 KB Output is correct
41 Correct 12 ms 3668 KB Output is correct
42 Correct 14 ms 3680 KB Output is correct
43 Correct 13 ms 3688 KB Output is correct
44 Correct 15 ms 3668 KB Output is correct
45 Correct 14 ms 3668 KB Output is correct
46 Correct 16 ms 3716 KB Output is correct
47 Correct 13 ms 3668 KB Output is correct
48 Correct 13 ms 3652 KB Output is correct
49 Correct 12 ms 3636 KB Output is correct
50 Correct 12 ms 3632 KB Output is correct
51 Correct 13 ms 3656 KB Output is correct
52 Correct 12 ms 3660 KB Output is correct
53 Correct 12 ms 3668 KB Output is correct
54 Correct 8 ms 2880 KB Output is correct
55 Correct 7 ms 2864 KB Output is correct
56 Correct 8 ms 2900 KB Output is correct
57 Correct 8 ms 2900 KB Output is correct
58 Correct 8 ms 2868 KB Output is correct
59 Correct 816 ms 19136 KB Output is correct
60 Correct 802 ms 19084 KB Output is correct
61 Correct 788 ms 18892 KB Output is correct
62 Correct 814 ms 19068 KB Output is correct
63 Correct 794 ms 19176 KB Output is correct
64 Correct 908 ms 19948 KB Output is correct
65 Correct 887 ms 19876 KB Output is correct
66 Correct 885 ms 19968 KB Output is correct
67 Correct 897 ms 19920 KB Output is correct
68 Correct 885 ms 19972 KB Output is correct
69 Correct 767 ms 19048 KB Output is correct
70 Correct 754 ms 19216 KB Output is correct
71 Correct 744 ms 19076 KB Output is correct
72 Correct 754 ms 19008 KB Output is correct
73 Correct 765 ms 19144 KB Output is correct
74 Correct 149 ms 10612 KB Output is correct
75 Correct 155 ms 10700 KB Output is correct
76 Correct 154 ms 10700 KB Output is correct
77 Correct 151 ms 10668 KB Output is correct
78 Correct 148 ms 10636 KB Output is correct