답안 #1086415

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086415 2024-09-10T14:37:43 Z Whisper Boat (APIO16_boat) C++17
100 / 100
866 ms 8532 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define REPD(i, a) for (int i = (a) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
#define MAX             2505
#define LIM             5005
int nArr;
vector<int> seg;
int l[MAX], r[MAX];

int dp[MAX * 2][MAX];
int inv[MAX];
int power(int a, int exp){
    int res = 1;
    for (; exp > 0; exp >>= 1, a = (1LL * a * a) % Mod) if(exp & 1){
        res = (1LL * res * a) % Mod;
    }
    return res;
}
void add(int &x, int y){
    x += y;
    if (x >= Mod) x %= Mod;
    while(x < 0) x += Mod;
}

int mul(int x, int y){
    return 1LL * x * y % Mod;
}

void process(void){
    cin >> nArr;
    for (int i = 1; i <= nArr; ++i){
        cin >> l[i] >> r[i];
        seg.emplace_back(l[i]);
        seg.emplace_back(r[i] + 1);
    }

    seg.emplace_back(0);
    sort(seg.begin(), seg.end());
    seg.resize(unique(seg.begin(), seg.end()) - seg.begin());

    for (int i = 0; i <= nArr; ++i) inv[i] = power(i, Mod - 2);
    for (int i = 0; i <= nArr; ++i) dp[0][i] = 1;
    int n = (int)seg.size();

    for (int i = 1; i < n - 1; ++i){
        int x = seg[i + 1] - seg[i];
        for (int pos = 0; pos <= nArr; ++pos){
            dp[i][pos] = dp[i - 1][pos];
            int nCk = 1, cnt = 0;
            for (int last = pos; last >= 1; --last){
                if (l[last] <= seg[i] && seg[i + 1] - 1 <= r[last]){
                    ++cnt;
                    nCk = mul(nCk, x + cnt - 1) * inv[cnt] % Mod;
                    add(dp[i][pos], mul(dp[i - 1][last - 1], nCk));
//                    add(dp[i][pos], mul(dp[i - 1][last - 1], C[x + cnt - 1][cnt]));
                }
            }
        }
    }
    /*
        C(x + cnt - 1, cnt)

        (x + cnt - 1)! / cnt! . (x - 1)!

        (x - 1 + 1) * (x - 1 + 2) .. * (x - 1 + cnt) / cnt!

    */
    cout << (dp[n - 2][nArr] - 1 + Mod) % Mod;
}
signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    // freopen(name".inp", "r", stdin);
    // freopen(name".out", "w", stdout);
    process();
    return (0 ^ 0);
}


# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 8276 KB Output is correct
2 Correct 142 ms 8276 KB Output is correct
3 Correct 136 ms 8276 KB Output is correct
4 Correct 134 ms 8276 KB Output is correct
5 Correct 180 ms 8256 KB Output is correct
6 Correct 129 ms 8332 KB Output is correct
7 Correct 114 ms 8272 KB Output is correct
8 Correct 119 ms 8272 KB Output is correct
9 Correct 115 ms 8344 KB Output is correct
10 Correct 116 ms 8304 KB Output is correct
11 Correct 121 ms 8272 KB Output is correct
12 Correct 115 ms 8276 KB Output is correct
13 Correct 120 ms 8272 KB Output is correct
14 Correct 107 ms 8412 KB Output is correct
15 Correct 115 ms 8272 KB Output is correct
16 Correct 23 ms 1880 KB Output is correct
17 Correct 25 ms 1836 KB Output is correct
18 Correct 23 ms 1844 KB Output is correct
19 Correct 30 ms 1880 KB Output is correct
20 Correct 26 ms 1872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 8276 KB Output is correct
2 Correct 142 ms 8276 KB Output is correct
3 Correct 136 ms 8276 KB Output is correct
4 Correct 134 ms 8276 KB Output is correct
5 Correct 180 ms 8256 KB Output is correct
6 Correct 129 ms 8332 KB Output is correct
7 Correct 114 ms 8272 KB Output is correct
8 Correct 119 ms 8272 KB Output is correct
9 Correct 115 ms 8344 KB Output is correct
10 Correct 116 ms 8304 KB Output is correct
11 Correct 121 ms 8272 KB Output is correct
12 Correct 115 ms 8276 KB Output is correct
13 Correct 120 ms 8272 KB Output is correct
14 Correct 107 ms 8412 KB Output is correct
15 Correct 115 ms 8272 KB Output is correct
16 Correct 23 ms 1880 KB Output is correct
17 Correct 25 ms 1836 KB Output is correct
18 Correct 23 ms 1844 KB Output is correct
19 Correct 30 ms 1880 KB Output is correct
20 Correct 26 ms 1872 KB Output is correct
21 Correct 538 ms 7508 KB Output is correct
22 Correct 529 ms 7768 KB Output is correct
23 Correct 499 ms 7508 KB Output is correct
24 Correct 525 ms 7548 KB Output is correct
25 Correct 557 ms 7608 KB Output is correct
26 Correct 729 ms 7292 KB Output is correct
27 Correct 735 ms 7508 KB Output is correct
28 Correct 735 ms 7512 KB Output is correct
29 Correct 727 ms 7248 KB Output is correct
30 Correct 121 ms 8272 KB Output is correct
31 Correct 113 ms 8272 KB Output is correct
32 Correct 124 ms 8244 KB Output is correct
33 Correct 127 ms 8404 KB Output is correct
34 Correct 114 ms 8184 KB Output is correct
35 Correct 129 ms 8268 KB Output is correct
36 Correct 134 ms 8276 KB Output is correct
37 Correct 131 ms 8272 KB Output is correct
38 Correct 126 ms 8288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1372 KB Output is correct
2 Correct 5 ms 1372 KB Output is correct
3 Correct 6 ms 1372 KB Output is correct
4 Correct 7 ms 1368 KB Output is correct
5 Correct 6 ms 1368 KB Output is correct
6 Correct 8 ms 1372 KB Output is correct
7 Correct 8 ms 1244 KB Output is correct
8 Correct 8 ms 1348 KB Output is correct
9 Correct 8 ms 1372 KB Output is correct
10 Correct 8 ms 1304 KB Output is correct
11 Correct 7 ms 1372 KB Output is correct
12 Correct 6 ms 1368 KB Output is correct
13 Correct 7 ms 1372 KB Output is correct
14 Correct 6 ms 1372 KB Output is correct
15 Correct 6 ms 1372 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 4 ms 860 KB Output is correct
19 Correct 3 ms 860 KB Output is correct
20 Correct 4 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 8276 KB Output is correct
2 Correct 142 ms 8276 KB Output is correct
3 Correct 136 ms 8276 KB Output is correct
4 Correct 134 ms 8276 KB Output is correct
5 Correct 180 ms 8256 KB Output is correct
6 Correct 129 ms 8332 KB Output is correct
7 Correct 114 ms 8272 KB Output is correct
8 Correct 119 ms 8272 KB Output is correct
9 Correct 115 ms 8344 KB Output is correct
10 Correct 116 ms 8304 KB Output is correct
11 Correct 121 ms 8272 KB Output is correct
12 Correct 115 ms 8276 KB Output is correct
13 Correct 120 ms 8272 KB Output is correct
14 Correct 107 ms 8412 KB Output is correct
15 Correct 115 ms 8272 KB Output is correct
16 Correct 23 ms 1880 KB Output is correct
17 Correct 25 ms 1836 KB Output is correct
18 Correct 23 ms 1844 KB Output is correct
19 Correct 30 ms 1880 KB Output is correct
20 Correct 26 ms 1872 KB Output is correct
21 Correct 538 ms 7508 KB Output is correct
22 Correct 529 ms 7768 KB Output is correct
23 Correct 499 ms 7508 KB Output is correct
24 Correct 525 ms 7548 KB Output is correct
25 Correct 557 ms 7608 KB Output is correct
26 Correct 729 ms 7292 KB Output is correct
27 Correct 735 ms 7508 KB Output is correct
28 Correct 735 ms 7512 KB Output is correct
29 Correct 727 ms 7248 KB Output is correct
30 Correct 121 ms 8272 KB Output is correct
31 Correct 113 ms 8272 KB Output is correct
32 Correct 124 ms 8244 KB Output is correct
33 Correct 127 ms 8404 KB Output is correct
34 Correct 114 ms 8184 KB Output is correct
35 Correct 129 ms 8268 KB Output is correct
36 Correct 134 ms 8276 KB Output is correct
37 Correct 131 ms 8272 KB Output is correct
38 Correct 126 ms 8288 KB Output is correct
39 Correct 7 ms 1372 KB Output is correct
40 Correct 5 ms 1372 KB Output is correct
41 Correct 6 ms 1372 KB Output is correct
42 Correct 7 ms 1368 KB Output is correct
43 Correct 6 ms 1368 KB Output is correct
44 Correct 8 ms 1372 KB Output is correct
45 Correct 8 ms 1244 KB Output is correct
46 Correct 8 ms 1348 KB Output is correct
47 Correct 8 ms 1372 KB Output is correct
48 Correct 8 ms 1304 KB Output is correct
49 Correct 7 ms 1372 KB Output is correct
50 Correct 6 ms 1368 KB Output is correct
51 Correct 7 ms 1372 KB Output is correct
52 Correct 6 ms 1372 KB Output is correct
53 Correct 6 ms 1372 KB Output is correct
54 Correct 4 ms 856 KB Output is correct
55 Correct 3 ms 860 KB Output is correct
56 Correct 4 ms 860 KB Output is correct
57 Correct 3 ms 860 KB Output is correct
58 Correct 4 ms 860 KB Output is correct
59 Correct 635 ms 8332 KB Output is correct
60 Correct 593 ms 8364 KB Output is correct
61 Correct 597 ms 8352 KB Output is correct
62 Correct 647 ms 8532 KB Output is correct
63 Correct 621 ms 8272 KB Output is correct
64 Correct 856 ms 8208 KB Output is correct
65 Correct 866 ms 8372 KB Output is correct
66 Correct 857 ms 8276 KB Output is correct
67 Correct 866 ms 8276 KB Output is correct
68 Correct 859 ms 8432 KB Output is correct
69 Correct 612 ms 8308 KB Output is correct
70 Correct 633 ms 8264 KB Output is correct
71 Correct 643 ms 8508 KB Output is correct
72 Correct 652 ms 8372 KB Output is correct
73 Correct 655 ms 8328 KB Output is correct
74 Correct 104 ms 1876 KB Output is correct
75 Correct 110 ms 1764 KB Output is correct
76 Correct 107 ms 1744 KB Output is correct
77 Correct 107 ms 1872 KB Output is correct
78 Correct 104 ms 1796 KB Output is correct