답안 #679243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679243 2023-01-07T21:11:15 Z stevancv Boat (APIO16_boat) C++14
58 / 100
2000 ms 4904 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sadd(a, b) a = Add(a, b)
#define smul(a, b) a = Mul(a, b)
using namespace std;
const int N = 500 + 2;
const int mod = 1e9 + 7;
int fak[N], inv[N];
int Add(int a, int b) {
    a += b;
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}
int Mul(int a, int b) {
    ll c = a; c *= b; c %= mod;
    return c;
}
int Exp(int a, int b) {
    int ans = 1;
    while (b > 0) {
        if (b & 1) smul(ans, a);
        smul(a, a);
        b >>= 1;
    }
    return ans;
}
int koef[2 * N][N], dp[N][2 * N];
bool pos[2 * N][N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    fak[0] = inv[0] = 1;
    for (int i = 1; i < N; i++) {
        fak[i] = Mul(fak[i - 1], i);
        inv[i] = Exp(fak[i], mod - 2);
    }
    int n; cin >> n;
    vector<int> a(n), b(n), all;
    all.push_back(-1);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        a[i] -= 1;
        all.push_back(a[i]);
        all.push_back(b[i]);
    }
    sort(all.begin(), all.end());
    all.erase(unique(all.begin(), all.end()), all.end());
    int x = all.size();
    for (int i = 1; i < x; i++) {
        int l = all[i] - all[i - 1];
        for (int j = 1; j <= n; j++) {
            int p = l, q = 1;
            for (int k = 1; k <= j; k++) {
                sadd(koef[i][j], Mul(Mul(p, inv[k]), Mul(q, inv[k - 1])));
                smul(p, l - k);
                smul(q, j - k);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        a[i] = lower_bound(all.begin(), all.end(), a[i]) - all.begin();
        b[i] = lower_bound(all.begin(), all.end(), b[i]) - all.begin();
    }
    for (int j = 0; j < x; j++) dp[0][j] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = a[i] + 1; j <= b[i]; j++) {
            int y = 1;
            for (int k = i; k >= 0; k--) {
                sadd(dp[i + 1][j], Mul(dp[k][j - 1], koef[j][y]));
                if (pos[j][k - 1]) y += 1;
            }
            pos[j][i] = 1;
        }
        for (int j = 1; j < x; j++) sadd(dp[i + 1][j], dp[i + 1][j - 1]);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) sadd(ans, dp[i][x - 1]);
    cout << ans << en;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1365 ms 4748 KB Output is correct
2 Correct 1407 ms 4700 KB Output is correct
3 Correct 1368 ms 4832 KB Output is correct
4 Correct 1375 ms 4720 KB Output is correct
5 Correct 1371 ms 4800 KB Output is correct
6 Correct 1376 ms 4760 KB Output is correct
7 Correct 1370 ms 4752 KB Output is correct
8 Correct 1364 ms 4672 KB Output is correct
9 Correct 1395 ms 4852 KB Output is correct
10 Correct 1374 ms 4688 KB Output is correct
11 Correct 1360 ms 4768 KB Output is correct
12 Correct 1370 ms 4868 KB Output is correct
13 Correct 1401 ms 4772 KB Output is correct
14 Correct 1372 ms 4860 KB Output is correct
15 Correct 1372 ms 4752 KB Output is correct
16 Correct 247 ms 2636 KB Output is correct
17 Correct 270 ms 2920 KB Output is correct
18 Correct 256 ms 2744 KB Output is correct
19 Correct 263 ms 2676 KB Output is correct
20 Correct 290 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1365 ms 4748 KB Output is correct
2 Correct 1407 ms 4700 KB Output is correct
3 Correct 1368 ms 4832 KB Output is correct
4 Correct 1375 ms 4720 KB Output is correct
5 Correct 1371 ms 4800 KB Output is correct
6 Correct 1376 ms 4760 KB Output is correct
7 Correct 1370 ms 4752 KB Output is correct
8 Correct 1364 ms 4672 KB Output is correct
9 Correct 1395 ms 4852 KB Output is correct
10 Correct 1374 ms 4688 KB Output is correct
11 Correct 1360 ms 4768 KB Output is correct
12 Correct 1370 ms 4868 KB Output is correct
13 Correct 1401 ms 4772 KB Output is correct
14 Correct 1372 ms 4860 KB Output is correct
15 Correct 1372 ms 4752 KB Output is correct
16 Correct 247 ms 2636 KB Output is correct
17 Correct 270 ms 2920 KB Output is correct
18 Correct 256 ms 2744 KB Output is correct
19 Correct 263 ms 2676 KB Output is correct
20 Correct 290 ms 2644 KB Output is correct
21 Correct 1232 ms 4504 KB Output is correct
22 Correct 1236 ms 4600 KB Output is correct
23 Correct 1190 ms 4528 KB Output is correct
24 Correct 1246 ms 4504 KB Output is correct
25 Correct 1223 ms 4472 KB Output is correct
26 Correct 1356 ms 4392 KB Output is correct
27 Correct 1350 ms 4484 KB Output is correct
28 Correct 1327 ms 4528 KB Output is correct
29 Correct 1345 ms 4556 KB Output is correct
30 Correct 1339 ms 4836 KB Output is correct
31 Correct 1360 ms 4784 KB Output is correct
32 Correct 1344 ms 4812 KB Output is correct
33 Correct 1384 ms 4904 KB Output is correct
34 Correct 1327 ms 4740 KB Output is correct
35 Correct 1324 ms 4760 KB Output is correct
36 Correct 1350 ms 4656 KB Output is correct
37 Correct 1351 ms 4812 KB Output is correct
38 Correct 1333 ms 4716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 1108 KB Output is correct
2 Correct 17 ms 1088 KB Output is correct
3 Correct 17 ms 1156 KB Output is correct
4 Correct 17 ms 1180 KB Output is correct
5 Correct 17 ms 1228 KB Output is correct
6 Correct 19 ms 1108 KB Output is correct
7 Correct 21 ms 1108 KB Output is correct
8 Correct 19 ms 1236 KB Output is correct
9 Correct 19 ms 1156 KB Output is correct
10 Correct 19 ms 1100 KB Output is correct
11 Correct 21 ms 1092 KB Output is correct
12 Correct 17 ms 1208 KB Output is correct
13 Correct 17 ms 1108 KB Output is correct
14 Correct 17 ms 1108 KB Output is correct
15 Correct 17 ms 1108 KB Output is correct
16 Correct 9 ms 928 KB Output is correct
17 Correct 9 ms 940 KB Output is correct
18 Correct 9 ms 980 KB Output is correct
19 Correct 10 ms 980 KB Output is correct
20 Correct 9 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1365 ms 4748 KB Output is correct
2 Correct 1407 ms 4700 KB Output is correct
3 Correct 1368 ms 4832 KB Output is correct
4 Correct 1375 ms 4720 KB Output is correct
5 Correct 1371 ms 4800 KB Output is correct
6 Correct 1376 ms 4760 KB Output is correct
7 Correct 1370 ms 4752 KB Output is correct
8 Correct 1364 ms 4672 KB Output is correct
9 Correct 1395 ms 4852 KB Output is correct
10 Correct 1374 ms 4688 KB Output is correct
11 Correct 1360 ms 4768 KB Output is correct
12 Correct 1370 ms 4868 KB Output is correct
13 Correct 1401 ms 4772 KB Output is correct
14 Correct 1372 ms 4860 KB Output is correct
15 Correct 1372 ms 4752 KB Output is correct
16 Correct 247 ms 2636 KB Output is correct
17 Correct 270 ms 2920 KB Output is correct
18 Correct 256 ms 2744 KB Output is correct
19 Correct 263 ms 2676 KB Output is correct
20 Correct 290 ms 2644 KB Output is correct
21 Correct 1232 ms 4504 KB Output is correct
22 Correct 1236 ms 4600 KB Output is correct
23 Correct 1190 ms 4528 KB Output is correct
24 Correct 1246 ms 4504 KB Output is correct
25 Correct 1223 ms 4472 KB Output is correct
26 Correct 1356 ms 4392 KB Output is correct
27 Correct 1350 ms 4484 KB Output is correct
28 Correct 1327 ms 4528 KB Output is correct
29 Correct 1345 ms 4556 KB Output is correct
30 Correct 1339 ms 4836 KB Output is correct
31 Correct 1360 ms 4784 KB Output is correct
32 Correct 1344 ms 4812 KB Output is correct
33 Correct 1384 ms 4904 KB Output is correct
34 Correct 1327 ms 4740 KB Output is correct
35 Correct 1324 ms 4760 KB Output is correct
36 Correct 1350 ms 4656 KB Output is correct
37 Correct 1351 ms 4812 KB Output is correct
38 Correct 1333 ms 4716 KB Output is correct
39 Correct 18 ms 1108 KB Output is correct
40 Correct 17 ms 1088 KB Output is correct
41 Correct 17 ms 1156 KB Output is correct
42 Correct 17 ms 1180 KB Output is correct
43 Correct 17 ms 1228 KB Output is correct
44 Correct 19 ms 1108 KB Output is correct
45 Correct 21 ms 1108 KB Output is correct
46 Correct 19 ms 1236 KB Output is correct
47 Correct 19 ms 1156 KB Output is correct
48 Correct 19 ms 1100 KB Output is correct
49 Correct 21 ms 1092 KB Output is correct
50 Correct 17 ms 1208 KB Output is correct
51 Correct 17 ms 1108 KB Output is correct
52 Correct 17 ms 1108 KB Output is correct
53 Correct 17 ms 1108 KB Output is correct
54 Correct 9 ms 928 KB Output is correct
55 Correct 9 ms 940 KB Output is correct
56 Correct 9 ms 980 KB Output is correct
57 Correct 10 ms 980 KB Output is correct
58 Correct 9 ms 980 KB Output is correct
59 Execution timed out 2008 ms 4732 KB Time limit exceeded
60 Halted 0 ms 0 KB -