답안 #512993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
512993 2022-01-16T21:13:15 Z TheScrasse Boat (APIO16_boat) C++17
100 / 100
1869 ms 24360 KB
#include <bits/stdc++.h>
using namespace std;

#define nl "\n"
#define nf endl
#define ll long long
#define pb push_back
#define _ << ' ' <<

#define INF (ll)1e18
#define mod 1000000007
#define maxn 2010

ll i, i1, j, k, k1, t, n, m, res, flag[10], a[maxn], b[maxn];
ll ps1[maxn][maxn], ps2[maxn][maxn], nv[maxn], l, r, dp, ln;
vector<ll> cm;
map<ll, ll> dc;

ll fxp(ll b, ll e) {
    ll r;
    if (e == 0) return 1;
    if (e % 2) {
        r = fxp(b, e - 1); return (b * r) % mod;
    } else {
        r = fxp(b, e / 2); return (r * r) % mod;
    }
}

ll inv(ll x) {
    return fxp(x, mod - 2);
}

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

    #if !ONLINE_JUDGE && !EVAL
        ifstream cin("input.txt");
        ofstream cout("output.txt");
    #endif

    for (i = 1; i < maxn; i++) nv[i] = inv(i);

    cin >> n; cm.pb(-1); cm.pb(0);
    for (i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        cm.pb(a[i] - 1); cm.pb(a[i]); cm.pb(b[i] - 1); cm.pb(b[i]);
    }

    sort(cm.begin(), cm.end());
    cm.resize(unique(cm.begin(), cm.end()) - cm.begin());

    for (i = 0; i < cm.size(); i++) dc[cm[i]] = i;
    for (i = 0; i <= n; i++) {
        a[i] = dc[a[i]]; b[i] = dc[b[i]];
    }

    // for (i = 0; i <= n; i++) cout << a[i] _ b[i] << nl;

    for (i = 0; i <= n; i++) {
        l = a[i]; r = b[i];
        for (j = 0; j <= 4 * n + 1; j++) {
            if (j >= l && j <= r) {
                ln = cm[j] - cm[j - 1];
                for (k = n; k >= 1; k--) {
                    if (i == 0) {
                        if (j == 1 && k == 1) dp = 1;
                    } else {
                        if (k == 1) dp = (ps1[i - 1][j - 1] * ln) % mod;
                        else dp = (((ps2[j][k - 1] * (ln - k + 1)) % mod) * nv[k]) % mod;
                    }
                    ps1[i][j] = (ps1[i][j] + dp) % mod;
                    ps2[j][k] = (ps2[j][k] + dp) % mod;
                    // if (dp != 0) cout << i _ j _ k _ dp << nl;
                }
            } else {
                dp = 0;
            }
            if (i >= 1) ps1[i][j] += ps1[i - 1][j];
            if (j >= 1) ps1[i][j] += ps1[i][j - 1];
            if (i >= 1 && j >= 1) ps1[i][j] -= ps1[i - 1][j - 1];
            ps1[i][j] = (ps1[i][j] + mod) % mod;
        }
    }

    cout << (ps1[n][4 * n + 1] + mod - 1) % mod << nl;

    return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:53:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for (i = 0; i < cm.size(); i++) dc[cm[i]] = i;
      |                 ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 12224 KB Output is correct
2 Correct 17 ms 12244 KB Output is correct
3 Correct 17 ms 12236 KB Output is correct
4 Correct 17 ms 12228 KB Output is correct
5 Correct 16 ms 12276 KB Output is correct
6 Correct 18 ms 12236 KB Output is correct
7 Correct 16 ms 12236 KB Output is correct
8 Correct 16 ms 12268 KB Output is correct
9 Correct 17 ms 12288 KB Output is correct
10 Correct 17 ms 12288 KB Output is correct
11 Correct 16 ms 12252 KB Output is correct
12 Correct 17 ms 12248 KB Output is correct
13 Correct 17 ms 12416 KB Output is correct
14 Correct 18 ms 12208 KB Output is correct
15 Correct 16 ms 12236 KB Output is correct
16 Correct 14 ms 8988 KB Output is correct
17 Correct 14 ms 8968 KB Output is correct
18 Correct 14 ms 8944 KB Output is correct
19 Correct 15 ms 8948 KB Output is correct
20 Correct 16 ms 8960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 12224 KB Output is correct
2 Correct 17 ms 12244 KB Output is correct
3 Correct 17 ms 12236 KB Output is correct
4 Correct 17 ms 12228 KB Output is correct
5 Correct 16 ms 12276 KB Output is correct
6 Correct 18 ms 12236 KB Output is correct
7 Correct 16 ms 12236 KB Output is correct
8 Correct 16 ms 12268 KB Output is correct
9 Correct 17 ms 12288 KB Output is correct
10 Correct 17 ms 12288 KB Output is correct
11 Correct 16 ms 12252 KB Output is correct
12 Correct 17 ms 12248 KB Output is correct
13 Correct 17 ms 12416 KB Output is correct
14 Correct 18 ms 12208 KB Output is correct
15 Correct 16 ms 12236 KB Output is correct
16 Correct 14 ms 8988 KB Output is correct
17 Correct 14 ms 8968 KB Output is correct
18 Correct 14 ms 8944 KB Output is correct
19 Correct 15 ms 8948 KB Output is correct
20 Correct 16 ms 8960 KB Output is correct
21 Correct 1193 ms 21592 KB Output is correct
22 Correct 1053 ms 21744 KB Output is correct
23 Correct 1010 ms 21380 KB Output is correct
24 Correct 1072 ms 21672 KB Output is correct
25 Correct 1063 ms 21500 KB Output is correct
26 Correct 1436 ms 20728 KB Output is correct
27 Correct 1457 ms 20772 KB Output is correct
28 Correct 1490 ms 20844 KB Output is correct
29 Correct 1508 ms 21024 KB Output is correct
30 Correct 33 ms 22980 KB Output is correct
31 Correct 33 ms 22968 KB Output is correct
32 Correct 32 ms 22912 KB Output is correct
33 Correct 32 ms 22980 KB Output is correct
34 Correct 31 ms 22848 KB Output is correct
35 Correct 21 ms 16172 KB Output is correct
36 Correct 27 ms 16208 KB Output is correct
37 Correct 23 ms 16200 KB Output is correct
38 Correct 22 ms 16128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 2960 KB Output is correct
2 Correct 14 ms 2956 KB Output is correct
3 Correct 12 ms 3020 KB Output is correct
4 Correct 12 ms 2992 KB Output is correct
5 Correct 13 ms 2996 KB Output is correct
6 Correct 17 ms 2892 KB Output is correct
7 Correct 17 ms 2948 KB Output is correct
8 Correct 18 ms 2968 KB Output is correct
9 Correct 22 ms 3004 KB Output is correct
10 Correct 17 ms 2892 KB Output is correct
11 Correct 14 ms 2988 KB Output is correct
12 Correct 12 ms 3020 KB Output is correct
13 Correct 15 ms 2984 KB Output is correct
14 Correct 13 ms 3008 KB Output is correct
15 Correct 13 ms 3000 KB Output is correct
16 Correct 6 ms 1884 KB Output is correct
17 Correct 6 ms 1868 KB Output is correct
18 Correct 6 ms 1820 KB Output is correct
19 Correct 6 ms 1880 KB Output is correct
20 Correct 7 ms 1892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 12224 KB Output is correct
2 Correct 17 ms 12244 KB Output is correct
3 Correct 17 ms 12236 KB Output is correct
4 Correct 17 ms 12228 KB Output is correct
5 Correct 16 ms 12276 KB Output is correct
6 Correct 18 ms 12236 KB Output is correct
7 Correct 16 ms 12236 KB Output is correct
8 Correct 16 ms 12268 KB Output is correct
9 Correct 17 ms 12288 KB Output is correct
10 Correct 17 ms 12288 KB Output is correct
11 Correct 16 ms 12252 KB Output is correct
12 Correct 17 ms 12248 KB Output is correct
13 Correct 17 ms 12416 KB Output is correct
14 Correct 18 ms 12208 KB Output is correct
15 Correct 16 ms 12236 KB Output is correct
16 Correct 14 ms 8988 KB Output is correct
17 Correct 14 ms 8968 KB Output is correct
18 Correct 14 ms 8944 KB Output is correct
19 Correct 15 ms 8948 KB Output is correct
20 Correct 16 ms 8960 KB Output is correct
21 Correct 1193 ms 21592 KB Output is correct
22 Correct 1053 ms 21744 KB Output is correct
23 Correct 1010 ms 21380 KB Output is correct
24 Correct 1072 ms 21672 KB Output is correct
25 Correct 1063 ms 21500 KB Output is correct
26 Correct 1436 ms 20728 KB Output is correct
27 Correct 1457 ms 20772 KB Output is correct
28 Correct 1490 ms 20844 KB Output is correct
29 Correct 1508 ms 21024 KB Output is correct
30 Correct 33 ms 22980 KB Output is correct
31 Correct 33 ms 22968 KB Output is correct
32 Correct 32 ms 22912 KB Output is correct
33 Correct 32 ms 22980 KB Output is correct
34 Correct 31 ms 22848 KB Output is correct
35 Correct 21 ms 16172 KB Output is correct
36 Correct 27 ms 16208 KB Output is correct
37 Correct 23 ms 16200 KB Output is correct
38 Correct 22 ms 16128 KB Output is correct
39 Correct 13 ms 2960 KB Output is correct
40 Correct 14 ms 2956 KB Output is correct
41 Correct 12 ms 3020 KB Output is correct
42 Correct 12 ms 2992 KB Output is correct
43 Correct 13 ms 2996 KB Output is correct
44 Correct 17 ms 2892 KB Output is correct
45 Correct 17 ms 2948 KB Output is correct
46 Correct 18 ms 2968 KB Output is correct
47 Correct 22 ms 3004 KB Output is correct
48 Correct 17 ms 2892 KB Output is correct
49 Correct 14 ms 2988 KB Output is correct
50 Correct 12 ms 3020 KB Output is correct
51 Correct 15 ms 2984 KB Output is correct
52 Correct 13 ms 3008 KB Output is correct
53 Correct 13 ms 3000 KB Output is correct
54 Correct 6 ms 1884 KB Output is correct
55 Correct 6 ms 1868 KB Output is correct
56 Correct 6 ms 1820 KB Output is correct
57 Correct 6 ms 1880 KB Output is correct
58 Correct 7 ms 1892 KB Output is correct
59 Correct 1309 ms 24272 KB Output is correct
60 Correct 1243 ms 24276 KB Output is correct
61 Correct 1212 ms 24244 KB Output is correct
62 Correct 1332 ms 24272 KB Output is correct
63 Correct 1274 ms 24136 KB Output is correct
64 Correct 1840 ms 24236 KB Output is correct
65 Correct 1869 ms 24224 KB Output is correct
66 Correct 1866 ms 24328 KB Output is correct
67 Correct 1868 ms 24328 KB Output is correct
68 Correct 1865 ms 24140 KB Output is correct
69 Correct 1189 ms 24316 KB Output is correct
70 Correct 1206 ms 24280 KB Output is correct
71 Correct 1209 ms 24196 KB Output is correct
72 Correct 1277 ms 24224 KB Output is correct
73 Correct 1267 ms 24360 KB Output is correct
74 Correct 143 ms 9856 KB Output is correct
75 Correct 139 ms 9840 KB Output is correct
76 Correct 138 ms 9792 KB Output is correct
77 Correct 139 ms 9848 KB Output is correct
78 Correct 148 ms 9796 KB Output is correct