Submission #1078378

# Submission time Handle Problem Language Result Execution time Memory
1078378 2024-08-27T16:02:54 Z underwaterkillerwhale Boat (APIO16_boat) C++17
100 / 100
631 ms 7508 KB
#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }

const int N = 5e2 + 7;
const int Mod = 1e9 + 7;
const int INF = 1e9;
const ll BASE = 137;
const int szBL = 320;

int n, m;
pii a[N];
int dp[N][N * 2], f[N][N * 2], com[N * 2][N], combi[N][N];

inline void add (int &a, int b) { a = a + b; if (a >= Mod) a = a - Mod; }

ll power (int n, int m) {
    if (m == 0) return 1;
    ll t = power (n, m >> 1);
    (t *= t) %= Mod;
    if (m & 1) (t *= n) %= Mod;
    return t;
}

bool cover (pii A, pii B) {
    return A.fs <= B.fs && A.se >= B.se;
}

void solution () {
    cin >> n;
    vector<pii> vec, seg = {MP(0, 0)};
    rep (i, 1, n) {
        cin >> a[i].fs >> a[i].se;
        vec.pb({a[i].fs, 0}), vec.pb({a[i].se, 1});
    }
    sort (ALL(vec));
    vec.resize(unique(ALL(vec)) - vec.begin());
    rep (i, 0, SZ(vec) - 2) {
        if (vec[i].se == vec[i + 1].se) {
            if (vec[i].se == 1) seg.pb({vec[i].fs + 1, vec[i + 1].fs});
            else seg.pb({vec[i].fs, vec[i + 1].fs - 1});
        }
        else {
            if (vec[i].se == 0) seg.pb({vec[i].fs, vec[i + 1].fs});
            else seg.pb({vec[i].fs + 1, vec[i +1 ].fs - 1});
        }
    }
    m = SZ(seg) - 1;
    rep (i, 0, m) {
        int Len = seg[i].se - seg[i].fs + 1;
        com[i][0] = 1;
        rep (j, 1, n + 1) {
            if (j > Len) com[i][j] = 0;
            else com[i][j] = 1LL * com[i][j - 1] * (Len - j + 1) % Mod * power (j, Mod - 2) % Mod;
        }
//        cout << seg[i].fs <<","<<seg[i].se<<"\n";
    }
    rep (i, 0, n) {
        rep (j, 0, i) {
            if (j == i || j == 0) combi[i][j] = 1;
            else combi[i][j] = (combi[i - 1][j - 1] + combi[i - 1][j]) % Mod;
        }
    }
    rep (i, 0, n) {
        rep (j, 0, m) {
            rep (k, 0, i) {
                add(f[i][j], 1LL * combi[i][k] * com[j][k + 1] % Mod);
            }
        }
    }
    rep (j, 0, m) dp[0][j] = 1;
    rep (i, 1, n) {
        dp[i][0] = 1;
        rep (j, 1, m) {
            dp[i][j] = dp[i][j - 1];
            int num = 0;
            reb (k, i, 1) {
                if (cover(a[k], seg[j])) {
                    add(dp[i][j], 1LL * dp[k - 1][j - 1] * f[num][j] % Mod);
                    ++num;
                }
            }
//            cout << i <<" "<<seg[j].fs<<","<<seg[j].se<<": "<<dp[i][j] <<"\n";
        }
    }
    cout << (dp[n][m] - 1 + Mod) % Mod <<"\n";

}


#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
int main () {
//    file("c");
    ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
}
/*
no bug challenge +4
mình có muốn dùng mảng này không?
4 5
1 3
4 1
1 2
3 2
2 1
return->break
*/
# Verdict Execution time Memory Grader output
1 Correct 402 ms 7252 KB Output is correct
2 Correct 417 ms 7252 KB Output is correct
3 Correct 408 ms 7248 KB Output is correct
4 Correct 425 ms 7504 KB Output is correct
5 Correct 431 ms 7252 KB Output is correct
6 Correct 396 ms 7504 KB Output is correct
7 Correct 389 ms 7344 KB Output is correct
8 Correct 401 ms 7328 KB Output is correct
9 Correct 403 ms 7504 KB Output is correct
10 Correct 389 ms 7248 KB Output is correct
11 Correct 403 ms 7268 KB Output is correct
12 Correct 401 ms 7248 KB Output is correct
13 Correct 395 ms 7252 KB Output is correct
14 Correct 385 ms 7416 KB Output is correct
15 Correct 398 ms 7380 KB Output is correct
16 Correct 75 ms 5716 KB Output is correct
17 Correct 83 ms 5712 KB Output is correct
18 Correct 80 ms 5772 KB Output is correct
19 Correct 81 ms 6104 KB Output is correct
20 Correct 80 ms 5712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 402 ms 7252 KB Output is correct
2 Correct 417 ms 7252 KB Output is correct
3 Correct 408 ms 7248 KB Output is correct
4 Correct 425 ms 7504 KB Output is correct
5 Correct 431 ms 7252 KB Output is correct
6 Correct 396 ms 7504 KB Output is correct
7 Correct 389 ms 7344 KB Output is correct
8 Correct 401 ms 7328 KB Output is correct
9 Correct 403 ms 7504 KB Output is correct
10 Correct 389 ms 7248 KB Output is correct
11 Correct 403 ms 7268 KB Output is correct
12 Correct 401 ms 7248 KB Output is correct
13 Correct 395 ms 7252 KB Output is correct
14 Correct 385 ms 7416 KB Output is correct
15 Correct 398 ms 7380 KB Output is correct
16 Correct 75 ms 5716 KB Output is correct
17 Correct 83 ms 5712 KB Output is correct
18 Correct 80 ms 5772 KB Output is correct
19 Correct 81 ms 6104 KB Output is correct
20 Correct 80 ms 5712 KB Output is correct
21 Correct 435 ms 7248 KB Output is correct
22 Correct 418 ms 7252 KB Output is correct
23 Correct 413 ms 7252 KB Output is correct
24 Correct 410 ms 7248 KB Output is correct
25 Correct 420 ms 7252 KB Output is correct
26 Correct 477 ms 7188 KB Output is correct
27 Correct 483 ms 7052 KB Output is correct
28 Correct 485 ms 7000 KB Output is correct
29 Correct 460 ms 7096 KB Output is correct
30 Correct 399 ms 7324 KB Output is correct
31 Correct 395 ms 7244 KB Output is correct
32 Correct 403 ms 7248 KB Output is correct
33 Correct 390 ms 7248 KB Output is correct
34 Correct 407 ms 7252 KB Output is correct
35 Correct 412 ms 7376 KB Output is correct
36 Correct 406 ms 7420 KB Output is correct
37 Correct 407 ms 7248 KB Output is correct
38 Correct 417 ms 7248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1880 KB Output is correct
2 Correct 9 ms 1884 KB Output is correct
3 Correct 9 ms 1744 KB Output is correct
4 Correct 8 ms 1664 KB Output is correct
5 Correct 10 ms 1884 KB Output is correct
6 Correct 9 ms 1884 KB Output is correct
7 Correct 9 ms 1880 KB Output is correct
8 Correct 9 ms 1884 KB Output is correct
9 Correct 9 ms 1884 KB Output is correct
10 Correct 10 ms 1884 KB Output is correct
11 Correct 9 ms 1748 KB Output is correct
12 Correct 9 ms 1884 KB Output is correct
13 Correct 8 ms 1628 KB Output is correct
14 Correct 9 ms 1884 KB Output is correct
15 Correct 11 ms 1892 KB Output is correct
16 Correct 5 ms 1628 KB Output is correct
17 Correct 4 ms 1604 KB Output is correct
18 Correct 5 ms 1628 KB Output is correct
19 Correct 6 ms 1536 KB Output is correct
20 Correct 4 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 402 ms 7252 KB Output is correct
2 Correct 417 ms 7252 KB Output is correct
3 Correct 408 ms 7248 KB Output is correct
4 Correct 425 ms 7504 KB Output is correct
5 Correct 431 ms 7252 KB Output is correct
6 Correct 396 ms 7504 KB Output is correct
7 Correct 389 ms 7344 KB Output is correct
8 Correct 401 ms 7328 KB Output is correct
9 Correct 403 ms 7504 KB Output is correct
10 Correct 389 ms 7248 KB Output is correct
11 Correct 403 ms 7268 KB Output is correct
12 Correct 401 ms 7248 KB Output is correct
13 Correct 395 ms 7252 KB Output is correct
14 Correct 385 ms 7416 KB Output is correct
15 Correct 398 ms 7380 KB Output is correct
16 Correct 75 ms 5716 KB Output is correct
17 Correct 83 ms 5712 KB Output is correct
18 Correct 80 ms 5772 KB Output is correct
19 Correct 81 ms 6104 KB Output is correct
20 Correct 80 ms 5712 KB Output is correct
21 Correct 435 ms 7248 KB Output is correct
22 Correct 418 ms 7252 KB Output is correct
23 Correct 413 ms 7252 KB Output is correct
24 Correct 410 ms 7248 KB Output is correct
25 Correct 420 ms 7252 KB Output is correct
26 Correct 477 ms 7188 KB Output is correct
27 Correct 483 ms 7052 KB Output is correct
28 Correct 485 ms 7000 KB Output is correct
29 Correct 460 ms 7096 KB Output is correct
30 Correct 399 ms 7324 KB Output is correct
31 Correct 395 ms 7244 KB Output is correct
32 Correct 403 ms 7248 KB Output is correct
33 Correct 390 ms 7248 KB Output is correct
34 Correct 407 ms 7252 KB Output is correct
35 Correct 412 ms 7376 KB Output is correct
36 Correct 406 ms 7420 KB Output is correct
37 Correct 407 ms 7248 KB Output is correct
38 Correct 417 ms 7248 KB Output is correct
39 Correct 8 ms 1880 KB Output is correct
40 Correct 9 ms 1884 KB Output is correct
41 Correct 9 ms 1744 KB Output is correct
42 Correct 8 ms 1664 KB Output is correct
43 Correct 10 ms 1884 KB Output is correct
44 Correct 9 ms 1884 KB Output is correct
45 Correct 9 ms 1880 KB Output is correct
46 Correct 9 ms 1884 KB Output is correct
47 Correct 9 ms 1884 KB Output is correct
48 Correct 10 ms 1884 KB Output is correct
49 Correct 9 ms 1748 KB Output is correct
50 Correct 9 ms 1884 KB Output is correct
51 Correct 8 ms 1628 KB Output is correct
52 Correct 9 ms 1884 KB Output is correct
53 Correct 11 ms 1892 KB Output is correct
54 Correct 5 ms 1628 KB Output is correct
55 Correct 4 ms 1604 KB Output is correct
56 Correct 5 ms 1628 KB Output is correct
57 Correct 6 ms 1536 KB Output is correct
58 Correct 4 ms 1628 KB Output is correct
59 Correct 528 ms 7316 KB Output is correct
60 Correct 530 ms 7248 KB Output is correct
61 Correct 532 ms 7248 KB Output is correct
62 Correct 538 ms 7252 KB Output is correct
63 Correct 531 ms 7248 KB Output is correct
64 Correct 630 ms 7380 KB Output is correct
65 Correct 623 ms 7348 KB Output is correct
66 Correct 621 ms 7248 KB Output is correct
67 Correct 631 ms 7424 KB Output is correct
68 Correct 626 ms 7252 KB Output is correct
69 Correct 548 ms 7244 KB Output is correct
70 Correct 559 ms 7360 KB Output is correct
71 Correct 560 ms 7508 KB Output is correct
72 Correct 563 ms 7508 KB Output is correct
73 Correct 553 ms 7252 KB Output is correct
74 Correct 95 ms 5716 KB Output is correct
75 Correct 96 ms 5660 KB Output is correct
76 Correct 96 ms 5748 KB Output is correct
77 Correct 95 ms 5716 KB Output is correct
78 Correct 92 ms 5716 KB Output is correct