답안 #294033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
294033 2020-09-08T14:34:35 Z Shafin666 Boat (APIO16_boat) C++14
100 / 100
609 ms 8440 KB
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<ll, ll>
#define nyan "(=^・ω・^=)"
#define read_input         freopen("in.txt","r", stdin)
#define print_output       freopen("out.txt","w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;

const ll mod = 1e9+7, maxn = 1e3+10;
ll l[maxn], r[maxn];
ll dp[maxn][maxn], sum[maxn][maxn];
ll ncr[maxn][maxn], inv[maxn];
vector<pii> edit;
vector<ll> v;

ll bigmod(ll a, ll b) {
    if(b == 0) return 1;
    ll x = bigmod(a, b/2);
    x = (x * x) % mod;
    if(b & 1) x = (x * a) % mod;
    return x;
}

int main() 
{
    ll n; cin >> n;
    for(ll i = 1; i <= n; i++) {
        cin >> l[i] >> r[i];
        v.pb(l[i]); v.pb(r[i]+1);
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    edit.pb({0, 0});
    for(ll i = 0; i < (ll)v.size()-1; i++) {
        edit.pb({v[i], v[i+1]-1});
    }
    ll m = edit.size() - 1;

    for(ll i = 1; i <= n; i++) inv[i] = bigmod(i, mod-2);

    dp[0][0] = 1;
    for(ll i = 0; i <= m; i++) sum[0][i] = 1;

    for(ll i = 1; i <= n; i++) {
        for(ll j = 1; j <= m; j++) {

            ll L = edit[j].second - edit[j].first + 1;
            ll cnt = 1, mul = L;

            if(!(l[i] <= edit[j].first && r[i] >= edit[j].second)) continue;

            for(ll k = i-1; k >= 0; k--) {
                dp[i][j] = (dp[i][j] + mul * sum[k][j-1]) % mod;
                if(l[k] <= edit[j].first && r[k] >= edit[j].second) {
                    cnt++;
                    mul = (mul * (L + cnt - 1)) % mod;
                    mul = (mul * inv[cnt]) % mod;
                }
            }
        }

        for(ll j = 1; j <= m; j++)
            sum[i][j] = (sum[i][j-1] + dp[i][j]) % mod;
    }

    ll ans = 0;
    for(ll i = 1; i <= n; i++) {
        for(ll j = 1; j <= m; j++)
            ans = (ans + dp[i][j]) % mod;
    }

    cout << ans << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 6272 KB Output is correct
2 Correct 13 ms 6272 KB Output is correct
3 Correct 13 ms 6272 KB Output is correct
4 Correct 13 ms 6400 KB Output is correct
5 Correct 13 ms 6272 KB Output is correct
6 Correct 13 ms 6400 KB Output is correct
7 Correct 13 ms 6400 KB Output is correct
8 Correct 13 ms 6400 KB Output is correct
9 Correct 13 ms 6400 KB Output is correct
10 Correct 14 ms 6400 KB Output is correct
11 Correct 13 ms 6400 KB Output is correct
12 Correct 13 ms 6400 KB Output is correct
13 Correct 13 ms 6400 KB Output is correct
14 Correct 14 ms 6400 KB Output is correct
15 Correct 13 ms 6400 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 8 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 6272 KB Output is correct
2 Correct 13 ms 6272 KB Output is correct
3 Correct 13 ms 6272 KB Output is correct
4 Correct 13 ms 6400 KB Output is correct
5 Correct 13 ms 6272 KB Output is correct
6 Correct 13 ms 6400 KB Output is correct
7 Correct 13 ms 6400 KB Output is correct
8 Correct 13 ms 6400 KB Output is correct
9 Correct 13 ms 6400 KB Output is correct
10 Correct 14 ms 6400 KB Output is correct
11 Correct 13 ms 6400 KB Output is correct
12 Correct 13 ms 6400 KB Output is correct
13 Correct 13 ms 6400 KB Output is correct
14 Correct 14 ms 6400 KB Output is correct
15 Correct 13 ms 6400 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 8 ms 5120 KB Output is correct
21 Correct 311 ms 7548 KB Output is correct
22 Correct 272 ms 7416 KB Output is correct
23 Correct 259 ms 7288 KB Output is correct
24 Correct 271 ms 7420 KB Output is correct
25 Correct 270 ms 7416 KB Output is correct
26 Correct 544 ms 8056 KB Output is correct
27 Correct 549 ms 8056 KB Output is correct
28 Correct 532 ms 8056 KB Output is correct
29 Correct 523 ms 8056 KB Output is correct
30 Correct 14 ms 6400 KB Output is correct
31 Correct 14 ms 6400 KB Output is correct
32 Correct 17 ms 6400 KB Output is correct
33 Correct 14 ms 6400 KB Output is correct
34 Correct 14 ms 6400 KB Output is correct
35 Correct 15 ms 6272 KB Output is correct
36 Correct 15 ms 6272 KB Output is correct
37 Correct 14 ms 6272 KB Output is correct
38 Correct 14 ms 6272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1408 KB Output is correct
2 Correct 3 ms 1408 KB Output is correct
3 Correct 4 ms 1408 KB Output is correct
4 Correct 4 ms 1408 KB Output is correct
5 Correct 5 ms 1408 KB Output is correct
6 Correct 6 ms 1408 KB Output is correct
7 Correct 7 ms 1408 KB Output is correct
8 Correct 6 ms 1408 KB Output is correct
9 Correct 6 ms 1408 KB Output is correct
10 Correct 6 ms 1408 KB Output is correct
11 Correct 4 ms 1408 KB Output is correct
12 Correct 3 ms 1408 KB Output is correct
13 Correct 4 ms 1408 KB Output is correct
14 Correct 4 ms 1408 KB Output is correct
15 Correct 4 ms 1408 KB Output is correct
16 Correct 3 ms 1280 KB Output is correct
17 Correct 3 ms 1280 KB Output is correct
18 Correct 3 ms 1280 KB Output is correct
19 Correct 3 ms 1280 KB Output is correct
20 Correct 4 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 6272 KB Output is correct
2 Correct 13 ms 6272 KB Output is correct
3 Correct 13 ms 6272 KB Output is correct
4 Correct 13 ms 6400 KB Output is correct
5 Correct 13 ms 6272 KB Output is correct
6 Correct 13 ms 6400 KB Output is correct
7 Correct 13 ms 6400 KB Output is correct
8 Correct 13 ms 6400 KB Output is correct
9 Correct 13 ms 6400 KB Output is correct
10 Correct 14 ms 6400 KB Output is correct
11 Correct 13 ms 6400 KB Output is correct
12 Correct 13 ms 6400 KB Output is correct
13 Correct 13 ms 6400 KB Output is correct
14 Correct 14 ms 6400 KB Output is correct
15 Correct 13 ms 6400 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 8 ms 5120 KB Output is correct
21 Correct 311 ms 7548 KB Output is correct
22 Correct 272 ms 7416 KB Output is correct
23 Correct 259 ms 7288 KB Output is correct
24 Correct 271 ms 7420 KB Output is correct
25 Correct 270 ms 7416 KB Output is correct
26 Correct 544 ms 8056 KB Output is correct
27 Correct 549 ms 8056 KB Output is correct
28 Correct 532 ms 8056 KB Output is correct
29 Correct 523 ms 8056 KB Output is correct
30 Correct 14 ms 6400 KB Output is correct
31 Correct 14 ms 6400 KB Output is correct
32 Correct 17 ms 6400 KB Output is correct
33 Correct 14 ms 6400 KB Output is correct
34 Correct 14 ms 6400 KB Output is correct
35 Correct 15 ms 6272 KB Output is correct
36 Correct 15 ms 6272 KB Output is correct
37 Correct 14 ms 6272 KB Output is correct
38 Correct 14 ms 6272 KB Output is correct
39 Correct 4 ms 1408 KB Output is correct
40 Correct 3 ms 1408 KB Output is correct
41 Correct 4 ms 1408 KB Output is correct
42 Correct 4 ms 1408 KB Output is correct
43 Correct 5 ms 1408 KB Output is correct
44 Correct 6 ms 1408 KB Output is correct
45 Correct 7 ms 1408 KB Output is correct
46 Correct 6 ms 1408 KB Output is correct
47 Correct 6 ms 1408 KB Output is correct
48 Correct 6 ms 1408 KB Output is correct
49 Correct 4 ms 1408 KB Output is correct
50 Correct 3 ms 1408 KB Output is correct
51 Correct 4 ms 1408 KB Output is correct
52 Correct 4 ms 1408 KB Output is correct
53 Correct 4 ms 1408 KB Output is correct
54 Correct 3 ms 1280 KB Output is correct
55 Correct 3 ms 1280 KB Output is correct
56 Correct 3 ms 1280 KB Output is correct
57 Correct 3 ms 1280 KB Output is correct
58 Correct 4 ms 1280 KB Output is correct
59 Correct 318 ms 7508 KB Output is correct
60 Correct 295 ms 7288 KB Output is correct
61 Correct 270 ms 7288 KB Output is correct
62 Correct 302 ms 7416 KB Output is correct
63 Correct 298 ms 7416 KB Output is correct
64 Correct 601 ms 8344 KB Output is correct
65 Correct 609 ms 8264 KB Output is correct
66 Correct 601 ms 8440 KB Output is correct
67 Correct 609 ms 8316 KB Output is correct
68 Correct 607 ms 8312 KB Output is correct
69 Correct 246 ms 7488 KB Output is correct
70 Correct 252 ms 7488 KB Output is correct
71 Correct 245 ms 7460 KB Output is correct
72 Correct 258 ms 7544 KB Output is correct
73 Correct 272 ms 7544 KB Output is correct
74 Correct 66 ms 5496 KB Output is correct
75 Correct 60 ms 5368 KB Output is correct
76 Correct 64 ms 5308 KB Output is correct
77 Correct 66 ms 5372 KB Output is correct
78 Correct 67 ms 5364 KB Output is correct