답안 #624385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
624385 2022-08-08T05:49:42 Z socpite Boat (APIO16_boat) C++14
100 / 100
1237 ms 8360 KB
#include<bits/stdc++.h>
using namespace std;

#define f first
#define s second

typedef long long ll;

const int maxn = 505;
const int mod = 1e9+7;

int n;

pair<int, int> A[maxn];
vector<int> cp;

ll dp[maxn][2*maxn], pc[2*maxn][maxn], inv[2*maxn];


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    inv[0] = inv[1] = 1;
    for(int i = 2; i < 2*maxn; i++)inv[i]=mod - inv[mod%i]*(mod/i)%mod;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> A[i].f >> A[i].s;
        cp.push_back(A[i].f-1);
        cp.push_back(A[i].s);
    }
    cp.push_back(0);
    sort(cp.begin(), cp.end());
    cp.erase(unique(cp.begin(), cp.end()), cp.end());
    for(int i = 1; i < cp.size(); i++){
        ll len = cp[i]-cp[i-1];
        pc[i][1] = len;
        int bound = 0;
        for(int j = 1; j <= n; j++){
            if(A[j].s >= cp[i] && A[j].f <= cp[i-1]+1)bound++;
        }
        for(int j = 2; j <= bound; j++){
            ll crr = len*(len-1)/2;
          	ll sum = 0;
            crr%=mod;
            for(int k = 2; k <= min(int(len), j); k++){
                sum += crr;
                // C(k-2, j-2)*C(k, len)
                if(sum >= mod)sum-=mod;
                crr=crr*(j-k)%mod*inv[k-1]%mod*(len-k)%mod*inv[k+1]%mod;
            }
          	pc[i][j]=sum;
        }
    }
    for(int i = 0; i < cp.size(); i++)dp[0][i]=1;
    for(int i = 0; i <= n; i++)dp[i][0]=1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j < cp.size(); j++){
            if(A[i].f > cp[j] || A[i].s <= cp[j-1])dp[i][j]=0;
            else{
                int cnt = 0;
                for(int k = i; k > 0; k--){
                    if(A[k].s >= cp[j] && A[k].f <= cp[j-1]+1){
                        cnt++;
                        dp[i][j]+=dp[k-1][j-1]*pc[j][cnt]%mod;
                        if(dp[i][j] >= mod)dp[i][j]-=mod;
                      	if(dp[i][j] < 0)dp[i][j]+=mod;
                    }
                }
            }
            //cout << i << " " << j << " " << dp[i][j] << endl;
            dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
            dp[i][j]%=mod;
        }
    }
    ll ans = dp[n][cp.size()-1]-1;
    ans%=mod;
    if(ans < 0)ans+=mod;
    cout << ans;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i = 1; i < cp.size(); i++){
      |                    ~~^~~~~~~~~~~
boat.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i = 0; i < cp.size(); i++)dp[0][i]=1;
      |                    ~~^~~~~~~~~~~
boat.cpp:58:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(int j = 1; j < cp.size(); j++){
      |                        ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8148 KB Output is correct
2 Correct 8 ms 8260 KB Output is correct
3 Correct 8 ms 8148 KB Output is correct
4 Correct 8 ms 8236 KB Output is correct
5 Correct 9 ms 8148 KB Output is correct
6 Correct 9 ms 8356 KB Output is correct
7 Correct 8 ms 8148 KB Output is correct
8 Correct 7 ms 8148 KB Output is correct
9 Correct 7 ms 8188 KB Output is correct
10 Correct 8 ms 8168 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 9 ms 8176 KB Output is correct
13 Correct 9 ms 8148 KB Output is correct
14 Correct 8 ms 8148 KB Output is correct
15 Correct 8 ms 8148 KB Output is correct
16 Correct 3 ms 3668 KB Output is correct
17 Correct 3 ms 3796 KB Output is correct
18 Correct 3 ms 3668 KB Output is correct
19 Correct 3 ms 3796 KB Output is correct
20 Correct 3 ms 3668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8148 KB Output is correct
2 Correct 8 ms 8260 KB Output is correct
3 Correct 8 ms 8148 KB Output is correct
4 Correct 8 ms 8236 KB Output is correct
5 Correct 9 ms 8148 KB Output is correct
6 Correct 9 ms 8356 KB Output is correct
7 Correct 8 ms 8148 KB Output is correct
8 Correct 7 ms 8148 KB Output is correct
9 Correct 7 ms 8188 KB Output is correct
10 Correct 8 ms 8168 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 9 ms 8176 KB Output is correct
13 Correct 9 ms 8148 KB Output is correct
14 Correct 8 ms 8148 KB Output is correct
15 Correct 8 ms 8148 KB Output is correct
16 Correct 3 ms 3668 KB Output is correct
17 Correct 3 ms 3796 KB Output is correct
18 Correct 3 ms 3668 KB Output is correct
19 Correct 3 ms 3796 KB Output is correct
20 Correct 3 ms 3668 KB Output is correct
21 Correct 288 ms 7872 KB Output is correct
22 Correct 293 ms 7936 KB Output is correct
23 Correct 246 ms 7860 KB Output is correct
24 Correct 279 ms 7852 KB Output is correct
25 Correct 293 ms 7884 KB Output is correct
26 Correct 294 ms 7920 KB Output is correct
27 Correct 316 ms 7768 KB Output is correct
28 Correct 313 ms 7656 KB Output is correct
29 Correct 323 ms 7760 KB Output is correct
30 Correct 8 ms 8244 KB Output is correct
31 Correct 8 ms 8176 KB Output is correct
32 Correct 9 ms 8160 KB Output is correct
33 Correct 8 ms 8148 KB Output is correct
34 Correct 8 ms 8148 KB Output is correct
35 Correct 9 ms 8180 KB Output is correct
36 Correct 9 ms 8276 KB Output is correct
37 Correct 10 ms 8168 KB Output is correct
38 Correct 9 ms 8124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1668 KB Output is correct
2 Correct 5 ms 1620 KB Output is correct
3 Correct 6 ms 1612 KB Output is correct
4 Correct 6 ms 1620 KB Output is correct
5 Correct 7 ms 1620 KB Output is correct
6 Correct 11 ms 1624 KB Output is correct
7 Correct 11 ms 1620 KB Output is correct
8 Correct 11 ms 1628 KB Output is correct
9 Correct 10 ms 1620 KB Output is correct
10 Correct 10 ms 1592 KB Output is correct
11 Correct 7 ms 1620 KB Output is correct
12 Correct 5 ms 1620 KB Output is correct
13 Correct 5 ms 1620 KB Output is correct
14 Correct 5 ms 1620 KB Output is correct
15 Correct 6 ms 1600 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 3 ms 1236 KB Output is correct
18 Correct 3 ms 1236 KB Output is correct
19 Correct 2 ms 1236 KB Output is correct
20 Correct 4 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8148 KB Output is correct
2 Correct 8 ms 8260 KB Output is correct
3 Correct 8 ms 8148 KB Output is correct
4 Correct 8 ms 8236 KB Output is correct
5 Correct 9 ms 8148 KB Output is correct
6 Correct 9 ms 8356 KB Output is correct
7 Correct 8 ms 8148 KB Output is correct
8 Correct 7 ms 8148 KB Output is correct
9 Correct 7 ms 8188 KB Output is correct
10 Correct 8 ms 8168 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 9 ms 8176 KB Output is correct
13 Correct 9 ms 8148 KB Output is correct
14 Correct 8 ms 8148 KB Output is correct
15 Correct 8 ms 8148 KB Output is correct
16 Correct 3 ms 3668 KB Output is correct
17 Correct 3 ms 3796 KB Output is correct
18 Correct 3 ms 3668 KB Output is correct
19 Correct 3 ms 3796 KB Output is correct
20 Correct 3 ms 3668 KB Output is correct
21 Correct 288 ms 7872 KB Output is correct
22 Correct 293 ms 7936 KB Output is correct
23 Correct 246 ms 7860 KB Output is correct
24 Correct 279 ms 7852 KB Output is correct
25 Correct 293 ms 7884 KB Output is correct
26 Correct 294 ms 7920 KB Output is correct
27 Correct 316 ms 7768 KB Output is correct
28 Correct 313 ms 7656 KB Output is correct
29 Correct 323 ms 7760 KB Output is correct
30 Correct 8 ms 8244 KB Output is correct
31 Correct 8 ms 8176 KB Output is correct
32 Correct 9 ms 8160 KB Output is correct
33 Correct 8 ms 8148 KB Output is correct
34 Correct 8 ms 8148 KB Output is correct
35 Correct 9 ms 8180 KB Output is correct
36 Correct 9 ms 8276 KB Output is correct
37 Correct 10 ms 8168 KB Output is correct
38 Correct 9 ms 8124 KB Output is correct
39 Correct 6 ms 1668 KB Output is correct
40 Correct 5 ms 1620 KB Output is correct
41 Correct 6 ms 1612 KB Output is correct
42 Correct 6 ms 1620 KB Output is correct
43 Correct 7 ms 1620 KB Output is correct
44 Correct 11 ms 1624 KB Output is correct
45 Correct 11 ms 1620 KB Output is correct
46 Correct 11 ms 1628 KB Output is correct
47 Correct 10 ms 1620 KB Output is correct
48 Correct 10 ms 1592 KB Output is correct
49 Correct 7 ms 1620 KB Output is correct
50 Correct 5 ms 1620 KB Output is correct
51 Correct 5 ms 1620 KB Output is correct
52 Correct 5 ms 1620 KB Output is correct
53 Correct 6 ms 1600 KB Output is correct
54 Correct 3 ms 1236 KB Output is correct
55 Correct 3 ms 1236 KB Output is correct
56 Correct 3 ms 1236 KB Output is correct
57 Correct 2 ms 1236 KB Output is correct
58 Correct 4 ms 1236 KB Output is correct
59 Correct 657 ms 8360 KB Output is correct
60 Correct 599 ms 8248 KB Output is correct
61 Correct 576 ms 8236 KB Output is correct
62 Correct 684 ms 8236 KB Output is correct
63 Correct 662 ms 8180 KB Output is correct
64 Correct 1164 ms 8136 KB Output is correct
65 Correct 1154 ms 8204 KB Output is correct
66 Correct 1201 ms 8240 KB Output is correct
67 Correct 1181 ms 8164 KB Output is correct
68 Correct 1237 ms 8136 KB Output is correct
69 Correct 560 ms 8156 KB Output is correct
70 Correct 542 ms 8236 KB Output is correct
71 Correct 548 ms 8172 KB Output is correct
72 Correct 570 ms 8240 KB Output is correct
73 Correct 563 ms 8220 KB Output is correct
74 Correct 84 ms 3744 KB Output is correct
75 Correct 79 ms 3736 KB Output is correct
76 Correct 78 ms 3736 KB Output is correct
77 Correct 80 ms 3692 KB Output is correct
78 Correct 84 ms 3744 KB Output is correct