답안 #199308

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199308 2020-01-30T23:17:33 Z osaaateiasavtnl Boat (APIO16_boat) C++14
100 / 100
968 ms 8696 KB
#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1007, MOD = 1000 * 1000 * 1000 + 7;
int fp(int a, int p) {
    ll ans = 1, c = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) ans = ans * c % MOD;
        c = c * c % MOD;
    }   
    return ans;
}   
int f[N], inv[N];
int n, l[N], r[N], dp[N][N], mem[N][N], cur[N], lmao[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    f[0] = inv[0] = 1;
    for (int i = 1; i < N; ++i) {
        f[i] = ((ll)f[i - 1] * i) % MOD;
        inv[i] = fp(f[i], MOD - 2);
    }   
    for (int i = 0; i < N; ++i)
        mem[i][0] = 1;
    for (int i = 1; i < N; ++i)
        for (int j = 1; j < N; ++j)
            mem[i][j] = (mem[i - 1][j] + mem[i - 1][j - 1]) % MOD;
    cin >> n;
    vector <int> c;
    for (int i = 1; i <= n; ++i) {
        cin >> l[i] >> r[i];
        c.app(l[i]); c.app(r[i] + 1);
    }                                
    sort(all(c));
    c.resize(unique(all(c)) - c.begin());
 
    dp[0][0] = 1;
    for (int i = 0; i + 1 < (int)c.size(); ++i) {   
        cur[0] = 1;
        ll t = 1;
        for (int j = 1; j <= n; ++j) {
            t = (t * (c[i + 1] - c[i] - j + 1)) % MOD;
            cur[j] = (t * inv[j]) % MOD;  
        }
        for (int mx = 1; mx <= n; ++mx) {
            lmao[mx] = 0;
            for (int cnt = 1; cnt <= mx; ++cnt)
                lmao[mx] = (lmao[mx] + (ll)mem[mx - 1][cnt - 1] * cur[cnt]) % MOD;
        }
        for (int j = 0; j <= n; ++j) {  
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
            int mx = 0;
            for (int k = j + 1; k <= n; ++k) {
                if (l[k] <= c[i] && c[i + 1] - 1 <= r[k]) { 
                    ++mx;
                    dp[i + 1][k] = (dp[i + 1][k] + (ll)dp[i][j] * lmao[mx]) % MOD;
                }   
            }
        }   
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        ans = (ans + dp[c.size() - 1][i]) % MOD;
    cout << ans << '\n';
}   
# 결과 실행 시간 메모리 Grader output
1 Correct 929 ms 8360 KB Output is correct
2 Correct 950 ms 8212 KB Output is correct
3 Correct 935 ms 8448 KB Output is correct
4 Correct 936 ms 8244 KB Output is correct
5 Correct 937 ms 8208 KB Output is correct
6 Correct 816 ms 8264 KB Output is correct
7 Correct 815 ms 8204 KB Output is correct
8 Correct 814 ms 8312 KB Output is correct
9 Correct 826 ms 8440 KB Output is correct
10 Correct 821 ms 8440 KB Output is correct
11 Correct 826 ms 8440 KB Output is correct
12 Correct 838 ms 8312 KB Output is correct
13 Correct 819 ms 8444 KB Output is correct
14 Correct 807 ms 8444 KB Output is correct
15 Correct 831 ms 8440 KB Output is correct
16 Correct 168 ms 4984 KB Output is correct
17 Correct 180 ms 5112 KB Output is correct
18 Correct 176 ms 5088 KB Output is correct
19 Correct 182 ms 5112 KB Output is correct
20 Correct 180 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 929 ms 8360 KB Output is correct
2 Correct 950 ms 8212 KB Output is correct
3 Correct 935 ms 8448 KB Output is correct
4 Correct 936 ms 8244 KB Output is correct
5 Correct 937 ms 8208 KB Output is correct
6 Correct 816 ms 8264 KB Output is correct
7 Correct 815 ms 8204 KB Output is correct
8 Correct 814 ms 8312 KB Output is correct
9 Correct 826 ms 8440 KB Output is correct
10 Correct 821 ms 8440 KB Output is correct
11 Correct 826 ms 8440 KB Output is correct
12 Correct 838 ms 8312 KB Output is correct
13 Correct 819 ms 8444 KB Output is correct
14 Correct 807 ms 8444 KB Output is correct
15 Correct 831 ms 8440 KB Output is correct
16 Correct 168 ms 4984 KB Output is correct
17 Correct 180 ms 5112 KB Output is correct
18 Correct 176 ms 5088 KB Output is correct
19 Correct 182 ms 5112 KB Output is correct
20 Correct 180 ms 5112 KB Output is correct
21 Correct 835 ms 8000 KB Output is correct
22 Correct 847 ms 8288 KB Output is correct
23 Correct 829 ms 8056 KB Output is correct
24 Correct 832 ms 7928 KB Output is correct
25 Correct 824 ms 8184 KB Output is correct
26 Correct 827 ms 7928 KB Output is correct
27 Correct 836 ms 8056 KB Output is correct
28 Correct 833 ms 7928 KB Output is correct
29 Correct 833 ms 7832 KB Output is correct
30 Correct 824 ms 8260 KB Output is correct
31 Correct 833 ms 8568 KB Output is correct
32 Correct 825 ms 8396 KB Output is correct
33 Correct 822 ms 8276 KB Output is correct
34 Correct 822 ms 8440 KB Output is correct
35 Correct 936 ms 8324 KB Output is correct
36 Correct 933 ms 8312 KB Output is correct
37 Correct 919 ms 8312 KB Output is correct
38 Correct 905 ms 8316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 5116 KB Output is correct
2 Correct 17 ms 5112 KB Output is correct
3 Correct 17 ms 5116 KB Output is correct
4 Correct 17 ms 5112 KB Output is correct
5 Correct 16 ms 5112 KB Output is correct
6 Correct 18 ms 5112 KB Output is correct
7 Correct 18 ms 5112 KB Output is correct
8 Correct 18 ms 5112 KB Output is correct
9 Correct 17 ms 5112 KB Output is correct
10 Correct 18 ms 5112 KB Output is correct
11 Correct 17 ms 5112 KB Output is correct
12 Correct 17 ms 5112 KB Output is correct
13 Correct 16 ms 5112 KB Output is correct
14 Correct 17 ms 5112 KB Output is correct
15 Correct 16 ms 5112 KB Output is correct
16 Correct 14 ms 4728 KB Output is correct
17 Correct 13 ms 4728 KB Output is correct
18 Correct 14 ms 4728 KB Output is correct
19 Correct 13 ms 4728 KB Output is correct
20 Correct 16 ms 4728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 929 ms 8360 KB Output is correct
2 Correct 950 ms 8212 KB Output is correct
3 Correct 935 ms 8448 KB Output is correct
4 Correct 936 ms 8244 KB Output is correct
5 Correct 937 ms 8208 KB Output is correct
6 Correct 816 ms 8264 KB Output is correct
7 Correct 815 ms 8204 KB Output is correct
8 Correct 814 ms 8312 KB Output is correct
9 Correct 826 ms 8440 KB Output is correct
10 Correct 821 ms 8440 KB Output is correct
11 Correct 826 ms 8440 KB Output is correct
12 Correct 838 ms 8312 KB Output is correct
13 Correct 819 ms 8444 KB Output is correct
14 Correct 807 ms 8444 KB Output is correct
15 Correct 831 ms 8440 KB Output is correct
16 Correct 168 ms 4984 KB Output is correct
17 Correct 180 ms 5112 KB Output is correct
18 Correct 176 ms 5088 KB Output is correct
19 Correct 182 ms 5112 KB Output is correct
20 Correct 180 ms 5112 KB Output is correct
21 Correct 835 ms 8000 KB Output is correct
22 Correct 847 ms 8288 KB Output is correct
23 Correct 829 ms 8056 KB Output is correct
24 Correct 832 ms 7928 KB Output is correct
25 Correct 824 ms 8184 KB Output is correct
26 Correct 827 ms 7928 KB Output is correct
27 Correct 836 ms 8056 KB Output is correct
28 Correct 833 ms 7928 KB Output is correct
29 Correct 833 ms 7832 KB Output is correct
30 Correct 824 ms 8260 KB Output is correct
31 Correct 833 ms 8568 KB Output is correct
32 Correct 825 ms 8396 KB Output is correct
33 Correct 822 ms 8276 KB Output is correct
34 Correct 822 ms 8440 KB Output is correct
35 Correct 936 ms 8324 KB Output is correct
36 Correct 933 ms 8312 KB Output is correct
37 Correct 919 ms 8312 KB Output is correct
38 Correct 905 ms 8316 KB Output is correct
39 Correct 17 ms 5116 KB Output is correct
40 Correct 17 ms 5112 KB Output is correct
41 Correct 17 ms 5116 KB Output is correct
42 Correct 17 ms 5112 KB Output is correct
43 Correct 16 ms 5112 KB Output is correct
44 Correct 18 ms 5112 KB Output is correct
45 Correct 18 ms 5112 KB Output is correct
46 Correct 18 ms 5112 KB Output is correct
47 Correct 17 ms 5112 KB Output is correct
48 Correct 18 ms 5112 KB Output is correct
49 Correct 17 ms 5112 KB Output is correct
50 Correct 17 ms 5112 KB Output is correct
51 Correct 16 ms 5112 KB Output is correct
52 Correct 17 ms 5112 KB Output is correct
53 Correct 16 ms 5112 KB Output is correct
54 Correct 14 ms 4728 KB Output is correct
55 Correct 13 ms 4728 KB Output is correct
56 Correct 14 ms 4728 KB Output is correct
57 Correct 13 ms 4728 KB Output is correct
58 Correct 16 ms 4728 KB Output is correct
59 Correct 921 ms 8440 KB Output is correct
60 Correct 914 ms 8312 KB Output is correct
61 Correct 916 ms 8440 KB Output is correct
62 Correct 921 ms 8440 KB Output is correct
63 Correct 914 ms 8440 KB Output is correct
64 Correct 942 ms 8440 KB Output is correct
65 Correct 931 ms 8440 KB Output is correct
66 Correct 968 ms 8440 KB Output is correct
67 Correct 939 ms 8440 KB Output is correct
68 Correct 954 ms 8440 KB Output is correct
69 Correct 897 ms 8312 KB Output is correct
70 Correct 908 ms 8696 KB Output is correct
71 Correct 902 ms 8376 KB Output is correct
72 Correct 890 ms 8236 KB Output is correct
73 Correct 916 ms 8392 KB Output is correct
74 Correct 180 ms 5068 KB Output is correct
75 Correct 183 ms 5112 KB Output is correct
76 Correct 179 ms 5112 KB Output is correct
77 Correct 172 ms 4984 KB Output is correct
78 Correct 172 ms 4984 KB Output is correct