답안 #1027530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027530 2024-07-19T07:20:10 Z _8_8_ Boat (APIO16_boat) C++17
58 / 100
2000 ms 22496 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
const int  N = 1e3 + 20, MOD = (int)1e9+7;

ll binpow(ll a,ll b) {
    ll ans = 1,k = a;
    while(b) {
        if(b % 2)ans *= k;
        ans %= MOD;
        k *= k;
        k %= MOD;
        b /= 2ll;
    }
    return ans;
}
ll bp[N];
ll mem[N][N];
ll ceis(ll n,ll k){
    if(k > n) return 0;
    if(n < N && mem[n][k]) return mem[n][k];     
    ll d = 1;
    for(ll i = n - k + 1;i <= n;i++){
        d = i % MOD * d % MOD;
    }
    for(ll i = 2;i <= k;i++){   
        d = d * bp[i]%MOD;
    }
    if(n < N){
        mem[n][k] = d;
    }
    return d;
}
int n;
array<int,2> a[N];
vector<int> b;
vector<array<int,2>> o;
ll dp[N][N],pref[N][N],c[N][N];
int m;
void test(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i][0] >> a[i][1];
        b.push_back(a[i][0]);
        b.push_back(a[i][1] + 1);
        bp[i] = binpow(i,MOD-2);
    }
    sort(b.begin(),b.end());
    b.resize(unique(b.begin(),b.end()) - b.begin()); 
    for(int i = 1;i < (int)b.size();i++){
        o.push_back({b[i-1],b[i]-1});
    }
    int m = (int)o.size();
    for(int i = 0;i <= m;i++){
        pref[0][i] = 1;
    }
    for(int i = 1;i <= m;i++){
        int s = (o[i - 1][1] - o[i - 1][0]+1);
        c[i][1] = s;
        vector<ll> C(n+1,0);
        for(int j = 0;j <= n;++j){
            C[j] = ceis(s,j);
        }
        for(int j = 2;j <= n;j++){
            for(int k = 0;k <= j-2;k++){
                c[i][j] = (c[i][j] + ceis(j-2,k)*C[j-k]%MOD)%MOD;
            }
        }
    }
    for(int i = 1;i <= n;i++){
        pref[i][0] = 1;
        for(int j = 1;j <= m;j++){
            dp[i][j] = dp[i - 1][j];
            if(a[i][0] <= o[j - 1][0] && a[i][1] >= o[j-1][1]){
                for(int k = i,col = 0;k >= 1;k--){
                    if(a[k][0] <= o[j-1][0] && a[k][1] >= o[j-1][1]){
                        ++col;
                        dp[i][j] += pref[k-1][j-1]*c[j][col]%MOD;
                        if(dp[j][j] >= MOD) dp[i][j] -= MOD;
                    }
                }
            }
        }
        for(int j = 1;j <= m;j++){
            pref[i][j] = (pref[i][j - 1] + dp[i][j])%MOD;
        }
    }
    cout << (pref[n][m]-1+MOD)%MOD << '\n';
}
signed main() {
    ios_base::sync_with_stdio(false);cin.tie(0);
    int t = 1; 
    // cin >> t;
    while(t--){
        test();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1246 ms 21620 KB Output is correct
2 Correct 1254 ms 21616 KB Output is correct
3 Correct 1211 ms 21808 KB Output is correct
4 Correct 1251 ms 21588 KB Output is correct
5 Correct 1245 ms 21584 KB Output is correct
6 Correct 1213 ms 21584 KB Output is correct
7 Correct 1227 ms 21612 KB Output is correct
8 Correct 1215 ms 21672 KB Output is correct
9 Correct 1226 ms 21588 KB Output is correct
10 Correct 1299 ms 21616 KB Output is correct
11 Correct 1297 ms 21588 KB Output is correct
12 Correct 1342 ms 21616 KB Output is correct
13 Correct 1198 ms 21752 KB Output is correct
14 Correct 1195 ms 21620 KB Output is correct
15 Correct 1188 ms 21620 KB Output is correct
16 Correct 376 ms 17108 KB Output is correct
17 Correct 379 ms 17236 KB Output is correct
18 Correct 370 ms 17104 KB Output is correct
19 Correct 387 ms 17080 KB Output is correct
20 Correct 369 ms 17232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1246 ms 21620 KB Output is correct
2 Correct 1254 ms 21616 KB Output is correct
3 Correct 1211 ms 21808 KB Output is correct
4 Correct 1251 ms 21588 KB Output is correct
5 Correct 1245 ms 21584 KB Output is correct
6 Correct 1213 ms 21584 KB Output is correct
7 Correct 1227 ms 21612 KB Output is correct
8 Correct 1215 ms 21672 KB Output is correct
9 Correct 1226 ms 21588 KB Output is correct
10 Correct 1299 ms 21616 KB Output is correct
11 Correct 1297 ms 21588 KB Output is correct
12 Correct 1342 ms 21616 KB Output is correct
13 Correct 1198 ms 21752 KB Output is correct
14 Correct 1195 ms 21620 KB Output is correct
15 Correct 1188 ms 21620 KB Output is correct
16 Correct 376 ms 17108 KB Output is correct
17 Correct 379 ms 17236 KB Output is correct
18 Correct 370 ms 17104 KB Output is correct
19 Correct 387 ms 17080 KB Output is correct
20 Correct 369 ms 17232 KB Output is correct
21 Correct 687 ms 21704 KB Output is correct
22 Correct 734 ms 21620 KB Output is correct
23 Correct 708 ms 21612 KB Output is correct
24 Correct 749 ms 21584 KB Output is correct
25 Correct 704 ms 21720 KB Output is correct
26 Correct 747 ms 21860 KB Output is correct
27 Correct 719 ms 21768 KB Output is correct
28 Correct 701 ms 21580 KB Output is correct
29 Correct 737 ms 21584 KB Output is correct
30 Correct 1165 ms 22496 KB Output is correct
31 Correct 1159 ms 22356 KB Output is correct
32 Correct 1071 ms 22356 KB Output is correct
33 Correct 1156 ms 22352 KB Output is correct
34 Correct 1196 ms 22244 KB Output is correct
35 Correct 1154 ms 22428 KB Output is correct
36 Correct 1111 ms 22356 KB Output is correct
37 Correct 1176 ms 22400 KB Output is correct
38 Correct 1132 ms 22252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 9564 KB Output is correct
2 Correct 17 ms 9564 KB Output is correct
3 Correct 17 ms 9556 KB Output is correct
4 Correct 16 ms 9564 KB Output is correct
5 Correct 17 ms 9560 KB Output is correct
6 Correct 17 ms 9560 KB Output is correct
7 Correct 17 ms 9564 KB Output is correct
8 Correct 17 ms 9556 KB Output is correct
9 Correct 17 ms 9564 KB Output is correct
10 Correct 18 ms 9564 KB Output is correct
11 Correct 16 ms 9816 KB Output is correct
12 Correct 15 ms 9564 KB Output is correct
13 Correct 14 ms 9568 KB Output is correct
14 Correct 15 ms 9564 KB Output is correct
15 Correct 18 ms 9564 KB Output is correct
16 Correct 10 ms 9564 KB Output is correct
17 Correct 9 ms 9496 KB Output is correct
18 Correct 10 ms 9564 KB Output is correct
19 Correct 10 ms 9444 KB Output is correct
20 Correct 10 ms 9496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1246 ms 21620 KB Output is correct
2 Correct 1254 ms 21616 KB Output is correct
3 Correct 1211 ms 21808 KB Output is correct
4 Correct 1251 ms 21588 KB Output is correct
5 Correct 1245 ms 21584 KB Output is correct
6 Correct 1213 ms 21584 KB Output is correct
7 Correct 1227 ms 21612 KB Output is correct
8 Correct 1215 ms 21672 KB Output is correct
9 Correct 1226 ms 21588 KB Output is correct
10 Correct 1299 ms 21616 KB Output is correct
11 Correct 1297 ms 21588 KB Output is correct
12 Correct 1342 ms 21616 KB Output is correct
13 Correct 1198 ms 21752 KB Output is correct
14 Correct 1195 ms 21620 KB Output is correct
15 Correct 1188 ms 21620 KB Output is correct
16 Correct 376 ms 17108 KB Output is correct
17 Correct 379 ms 17236 KB Output is correct
18 Correct 370 ms 17104 KB Output is correct
19 Correct 387 ms 17080 KB Output is correct
20 Correct 369 ms 17232 KB Output is correct
21 Correct 687 ms 21704 KB Output is correct
22 Correct 734 ms 21620 KB Output is correct
23 Correct 708 ms 21612 KB Output is correct
24 Correct 749 ms 21584 KB Output is correct
25 Correct 704 ms 21720 KB Output is correct
26 Correct 747 ms 21860 KB Output is correct
27 Correct 719 ms 21768 KB Output is correct
28 Correct 701 ms 21580 KB Output is correct
29 Correct 737 ms 21584 KB Output is correct
30 Correct 1165 ms 22496 KB Output is correct
31 Correct 1159 ms 22356 KB Output is correct
32 Correct 1071 ms 22356 KB Output is correct
33 Correct 1156 ms 22352 KB Output is correct
34 Correct 1196 ms 22244 KB Output is correct
35 Correct 1154 ms 22428 KB Output is correct
36 Correct 1111 ms 22356 KB Output is correct
37 Correct 1176 ms 22400 KB Output is correct
38 Correct 1132 ms 22252 KB Output is correct
39 Correct 17 ms 9564 KB Output is correct
40 Correct 17 ms 9564 KB Output is correct
41 Correct 17 ms 9556 KB Output is correct
42 Correct 16 ms 9564 KB Output is correct
43 Correct 17 ms 9560 KB Output is correct
44 Correct 17 ms 9560 KB Output is correct
45 Correct 17 ms 9564 KB Output is correct
46 Correct 17 ms 9556 KB Output is correct
47 Correct 17 ms 9564 KB Output is correct
48 Correct 18 ms 9564 KB Output is correct
49 Correct 16 ms 9816 KB Output is correct
50 Correct 15 ms 9564 KB Output is correct
51 Correct 14 ms 9568 KB Output is correct
52 Correct 15 ms 9564 KB Output is correct
53 Correct 18 ms 9564 KB Output is correct
54 Correct 10 ms 9564 KB Output is correct
55 Correct 9 ms 9496 KB Output is correct
56 Correct 10 ms 9564 KB Output is correct
57 Correct 10 ms 9444 KB Output is correct
58 Correct 10 ms 9496 KB Output is correct
59 Correct 1882 ms 21588 KB Output is correct
60 Correct 1901 ms 21644 KB Output is correct
61 Correct 1891 ms 21588 KB Output is correct
62 Correct 1891 ms 21588 KB Output is correct
63 Correct 1895 ms 21588 KB Output is correct
64 Correct 1945 ms 21588 KB Output is correct
65 Execution timed out 2036 ms 21512 KB Time limit exceeded
66 Halted 0 ms 0 KB -