Submission #960425

# Submission time Handle Problem Language Result Execution time Memory
960425 2024-04-10T12:38:53 Z kim Boat (APIO16_boat) C++17
100 / 100
724 ms 14228 KB
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define eb emplace_back

const ll md=1e9+7;

vector<int> comp;
int a[505],b[505];
ll dp[505][1005],inv[505],C[505][505],f[1005][505],g[1005][505];

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

    int n; cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i]>>b[i];
        comp.eb(--a[i]), comp.eb(b[i]);
    }
    comp.eb(0);
    sort(comp.begin(),comp.end());
    comp.erase(unique(comp.begin(),comp.end()),comp.end());

    C[0][0]=1;
    for(int i=1;i<=n;++i){
        inv[i]=1;
        ll a=i,b=md-2;
        for(;b>0;b>>=1,a=(a*a)%md) if(b&1) inv[i]=(inv[i]*a)%md;
        C[i][0]=1;
        for(int j=1;j<=n;++j) C[i][j]=(C[i-1][j-1]+C[i-1][j])%md;
    }
    for(int i=1;i<comp.size();++i){
        int cur=comp[i]-comp[i-1];
        f[i][1]=cur--;
        for(int j=2;j<=n&&cur>0;++j) f[i][j]=((((f[i][j-1]*(cur--))%md)*inv[j])%md+md)%md;
        for(int j=1;j<=n;++j){
            int m=min(j,comp[i]-comp[i-1]);
            for(int k=1;k<=m;++k) g[i][j]=(g[i][j]+f[i][k]*C[j-1][k-1])%md;
        }
    }

    ll ans=0;
    for(int i=1;i<=n;++i){
        a[i]=lower_bound(comp.begin(),comp.end(),a[i])-comp.begin();
        b[i]=lower_bound(comp.begin(),comp.end(),b[i])-comp.begin();
    
        for(int j=a[i]+1;j<=b[i];++j){
            int cnt=1;
            for(int k=i-1;k>0;--k){
                if(a[k]<j-1) dp[i][j]=(dp[i][j]+dp[k][min(b[k],j-1)]*g[j][cnt])%md;
                if(a[k]<j&&j<=b[k]) ++cnt;
            }
            dp[i][j]=(dp[i][j]+dp[i][j-1]+g[j][cnt])%md;
        }
        ans=(ans+dp[i][b[i]])%md;
    }
    cout<<ans;

    return 0;
}
/*

f[j][1]*C[cnt-1][1-1] + f[j][2]*C[cnt-1][2-1] + f[j][3]*C[cnt-1][3-1] + ... + f[j][min(m,cnt)]*C[cnt-1][min(m,cnt)-1]

f[1][1]*C[1][0]+f[1][2]*C[1][1]

*/

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:32:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i=1;i<comp.size();++i){
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 240 ms 12432 KB Output is correct
2 Correct 241 ms 12368 KB Output is correct
3 Correct 239 ms 12436 KB Output is correct
4 Correct 240 ms 12452 KB Output is correct
5 Correct 238 ms 12436 KB Output is correct
6 Correct 239 ms 12628 KB Output is correct
7 Correct 239 ms 12428 KB Output is correct
8 Correct 241 ms 12560 KB Output is correct
9 Correct 239 ms 12552 KB Output is correct
10 Correct 238 ms 12624 KB Output is correct
11 Correct 244 ms 12428 KB Output is correct
12 Correct 239 ms 12560 KB Output is correct
13 Correct 240 ms 12628 KB Output is correct
14 Correct 239 ms 12628 KB Output is correct
15 Correct 241 ms 12428 KB Output is correct
16 Correct 46 ms 11028 KB Output is correct
17 Correct 49 ms 11088 KB Output is correct
18 Correct 47 ms 10920 KB Output is correct
19 Correct 48 ms 11180 KB Output is correct
20 Correct 47 ms 10912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 240 ms 12432 KB Output is correct
2 Correct 241 ms 12368 KB Output is correct
3 Correct 239 ms 12436 KB Output is correct
4 Correct 240 ms 12452 KB Output is correct
5 Correct 238 ms 12436 KB Output is correct
6 Correct 239 ms 12628 KB Output is correct
7 Correct 239 ms 12428 KB Output is correct
8 Correct 241 ms 12560 KB Output is correct
9 Correct 239 ms 12552 KB Output is correct
10 Correct 238 ms 12624 KB Output is correct
11 Correct 244 ms 12428 KB Output is correct
12 Correct 239 ms 12560 KB Output is correct
13 Correct 240 ms 12628 KB Output is correct
14 Correct 239 ms 12628 KB Output is correct
15 Correct 241 ms 12428 KB Output is correct
16 Correct 46 ms 11028 KB Output is correct
17 Correct 49 ms 11088 KB Output is correct
18 Correct 47 ms 10920 KB Output is correct
19 Correct 48 ms 11180 KB Output is correct
20 Correct 47 ms 10912 KB Output is correct
21 Correct 147 ms 13420 KB Output is correct
22 Correct 133 ms 13320 KB Output is correct
23 Correct 138 ms 13408 KB Output is correct
24 Correct 140 ms 13392 KB Output is correct
25 Correct 132 ms 13392 KB Output is correct
26 Correct 231 ms 14100 KB Output is correct
27 Correct 234 ms 14000 KB Output is correct
28 Correct 232 ms 13916 KB Output is correct
29 Correct 227 ms 13964 KB Output is correct
30 Correct 228 ms 12468 KB Output is correct
31 Correct 232 ms 12668 KB Output is correct
32 Correct 235 ms 12576 KB Output is correct
33 Correct 231 ms 12516 KB Output is correct
34 Correct 232 ms 12592 KB Output is correct
35 Correct 225 ms 12592 KB Output is correct
36 Correct 228 ms 12444 KB Output is correct
37 Correct 230 ms 12440 KB Output is correct
38 Correct 228 ms 12472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9560 KB Output is correct
2 Correct 7 ms 9564 KB Output is correct
3 Correct 7 ms 9564 KB Output is correct
4 Correct 7 ms 9560 KB Output is correct
5 Correct 7 ms 9564 KB Output is correct
6 Correct 8 ms 9564 KB Output is correct
7 Correct 8 ms 9452 KB Output is correct
8 Correct 8 ms 9560 KB Output is correct
9 Correct 8 ms 9564 KB Output is correct
10 Correct 8 ms 9640 KB Output is correct
11 Correct 7 ms 9816 KB Output is correct
12 Correct 6 ms 9564 KB Output is correct
13 Correct 7 ms 9560 KB Output is correct
14 Correct 7 ms 9564 KB Output is correct
15 Correct 7 ms 9540 KB Output is correct
16 Correct 4 ms 9304 KB Output is correct
17 Correct 6 ms 9052 KB Output is correct
18 Correct 4 ms 9052 KB Output is correct
19 Correct 4 ms 9060 KB Output is correct
20 Correct 4 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 240 ms 12432 KB Output is correct
2 Correct 241 ms 12368 KB Output is correct
3 Correct 239 ms 12436 KB Output is correct
4 Correct 240 ms 12452 KB Output is correct
5 Correct 238 ms 12436 KB Output is correct
6 Correct 239 ms 12628 KB Output is correct
7 Correct 239 ms 12428 KB Output is correct
8 Correct 241 ms 12560 KB Output is correct
9 Correct 239 ms 12552 KB Output is correct
10 Correct 238 ms 12624 KB Output is correct
11 Correct 244 ms 12428 KB Output is correct
12 Correct 239 ms 12560 KB Output is correct
13 Correct 240 ms 12628 KB Output is correct
14 Correct 239 ms 12628 KB Output is correct
15 Correct 241 ms 12428 KB Output is correct
16 Correct 46 ms 11028 KB Output is correct
17 Correct 49 ms 11088 KB Output is correct
18 Correct 47 ms 10920 KB Output is correct
19 Correct 48 ms 11180 KB Output is correct
20 Correct 47 ms 10912 KB Output is correct
21 Correct 147 ms 13420 KB Output is correct
22 Correct 133 ms 13320 KB Output is correct
23 Correct 138 ms 13408 KB Output is correct
24 Correct 140 ms 13392 KB Output is correct
25 Correct 132 ms 13392 KB Output is correct
26 Correct 231 ms 14100 KB Output is correct
27 Correct 234 ms 14000 KB Output is correct
28 Correct 232 ms 13916 KB Output is correct
29 Correct 227 ms 13964 KB Output is correct
30 Correct 228 ms 12468 KB Output is correct
31 Correct 232 ms 12668 KB Output is correct
32 Correct 235 ms 12576 KB Output is correct
33 Correct 231 ms 12516 KB Output is correct
34 Correct 232 ms 12592 KB Output is correct
35 Correct 225 ms 12592 KB Output is correct
36 Correct 228 ms 12444 KB Output is correct
37 Correct 230 ms 12440 KB Output is correct
38 Correct 228 ms 12472 KB Output is correct
39 Correct 7 ms 9560 KB Output is correct
40 Correct 7 ms 9564 KB Output is correct
41 Correct 7 ms 9564 KB Output is correct
42 Correct 7 ms 9560 KB Output is correct
43 Correct 7 ms 9564 KB Output is correct
44 Correct 8 ms 9564 KB Output is correct
45 Correct 8 ms 9452 KB Output is correct
46 Correct 8 ms 9560 KB Output is correct
47 Correct 8 ms 9564 KB Output is correct
48 Correct 8 ms 9640 KB Output is correct
49 Correct 7 ms 9816 KB Output is correct
50 Correct 6 ms 9564 KB Output is correct
51 Correct 7 ms 9560 KB Output is correct
52 Correct 7 ms 9564 KB Output is correct
53 Correct 7 ms 9540 KB Output is correct
54 Correct 4 ms 9304 KB Output is correct
55 Correct 6 ms 9052 KB Output is correct
56 Correct 4 ms 9052 KB Output is correct
57 Correct 4 ms 9060 KB Output is correct
58 Correct 4 ms 9052 KB Output is correct
59 Correct 615 ms 13436 KB Output is correct
60 Correct 606 ms 13604 KB Output is correct
61 Correct 588 ms 13456 KB Output is correct
62 Correct 619 ms 13336 KB Output is correct
63 Correct 605 ms 13488 KB Output is correct
64 Correct 722 ms 14228 KB Output is correct
65 Correct 722 ms 14200 KB Output is correct
66 Correct 714 ms 14220 KB Output is correct
67 Correct 724 ms 14088 KB Output is correct
68 Correct 719 ms 14120 KB Output is correct
69 Correct 604 ms 13412 KB Output is correct
70 Correct 601 ms 13456 KB Output is correct
71 Correct 594 ms 13308 KB Output is correct
72 Correct 605 ms 13540 KB Output is correct
73 Correct 603 ms 13452 KB Output is correct
74 Correct 80 ms 11096 KB Output is correct
75 Correct 77 ms 11092 KB Output is correct
76 Correct 83 ms 11548 KB Output is correct
77 Correct 79 ms 11348 KB Output is correct
78 Correct 84 ms 11344 KB Output is correct