Submission #632413

# Submission time Handle Problem Language Result Execution time Memory
632413 2022-08-20T02:01:27 Z bachhoangxuan Boat (APIO16_boat) C++17
100 / 100
730 ms 8388 KB
#include<bits/stdc++.h>
using namespace std;
#define maxn 505
#define int long long
const int mod=1e9+7;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=(res*a)%mod;
        a=(a*a)%mod;n>>=1;
    }
    return res;
}
vector<int> x;
int n,l[maxn],r[maxn],dp[maxn][2*maxn],divs[maxn],sum[maxn][2*maxn];
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin >> n;divs[0]=1;
    for(int i=1;i<=n;i++){
        cin >> l[i] >> r[i];
        divs[i]=power(i,mod-2)%mod;r[i]++;
        x.push_back(l[i]);x.push_back(r[i]);
    }
    sort(x.begin(),x.end());
    x.erase(unique(x.begin(),x.end()),x.end());
    int m=(int)x.size();
    for(int i=1;i<=n;i++){
        l[i]=lower_bound(x.begin(),x.end(),l[i])-x.begin()+1;
        r[i]=lower_bound(x.begin(),x.end(),r[i])-x.begin();
    }
    dp[0][0]=1;
    for(int i=0;i<m;i++) sum[0][i]=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<m;j++){
            int mul=1,len=x[j]-x[j-1],cnt=0;
            for(int k=i;k>=1;k--){
                if(j<l[k] || j>r[k]) continue;
                mul=mul*(len+cnt)%mod*divs[++cnt]%mod;
                dp[i][j]=(dp[i][j]+sum[k-1][j-1]*mul)%mod;
            }
        }
        sum[i][0]=dp[i][0]=1;
        for(int j=1;j<m;j++) sum[i][j]=(dp[i][j]+sum[i][j-1])%mod;
    }
    cout << (sum[n][m-1]+mod-1)%mod << '\n';
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:39:44: warning: operation on 'cnt' may be undefined [-Wsequence-point]
   39 |                 mul=mul*(len+cnt)%mod*divs[++cnt]%mod;
      |                                            ^~~~~
boat.cpp:39:44: warning: operation on 'cnt' may be undefined [-Wsequence-point]
# Verdict Execution time Memory Grader output
1 Correct 263 ms 8192 KB Output is correct
2 Correct 256 ms 8172 KB Output is correct
3 Correct 283 ms 8268 KB Output is correct
4 Correct 300 ms 8180 KB Output is correct
5 Correct 253 ms 8204 KB Output is correct
6 Correct 164 ms 8320 KB Output is correct
7 Correct 156 ms 8012 KB Output is correct
8 Correct 161 ms 8084 KB Output is correct
9 Correct 171 ms 8260 KB Output is correct
10 Correct 161 ms 8276 KB Output is correct
11 Correct 160 ms 7964 KB Output is correct
12 Correct 165 ms 8128 KB Output is correct
13 Correct 156 ms 7980 KB Output is correct
14 Correct 153 ms 8292 KB Output is correct
15 Correct 181 ms 8120 KB Output is correct
16 Correct 56 ms 5712 KB Output is correct
17 Correct 56 ms 5716 KB Output is correct
18 Correct 69 ms 5752 KB Output is correct
19 Correct 58 ms 5780 KB Output is correct
20 Correct 56 ms 5820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 263 ms 8192 KB Output is correct
2 Correct 256 ms 8172 KB Output is correct
3 Correct 283 ms 8268 KB Output is correct
4 Correct 300 ms 8180 KB Output is correct
5 Correct 253 ms 8204 KB Output is correct
6 Correct 164 ms 8320 KB Output is correct
7 Correct 156 ms 8012 KB Output is correct
8 Correct 161 ms 8084 KB Output is correct
9 Correct 171 ms 8260 KB Output is correct
10 Correct 161 ms 8276 KB Output is correct
11 Correct 160 ms 7964 KB Output is correct
12 Correct 165 ms 8128 KB Output is correct
13 Correct 156 ms 7980 KB Output is correct
14 Correct 153 ms 8292 KB Output is correct
15 Correct 181 ms 8120 KB Output is correct
16 Correct 56 ms 5712 KB Output is correct
17 Correct 56 ms 5716 KB Output is correct
18 Correct 69 ms 5752 KB Output is correct
19 Correct 58 ms 5780 KB Output is correct
20 Correct 56 ms 5820 KB Output is correct
21 Correct 448 ms 8268 KB Output is correct
22 Correct 445 ms 8300 KB Output is correct
23 Correct 431 ms 8152 KB Output is correct
24 Correct 441 ms 8228 KB Output is correct
25 Correct 478 ms 8196 KB Output is correct
26 Correct 617 ms 8184 KB Output is correct
27 Correct 665 ms 8208 KB Output is correct
28 Correct 630 ms 8284 KB Output is correct
29 Correct 614 ms 8228 KB Output is correct
30 Correct 177 ms 8196 KB Output is correct
31 Correct 172 ms 7928 KB Output is correct
32 Correct 157 ms 8012 KB Output is correct
33 Correct 159 ms 8056 KB Output is correct
34 Correct 184 ms 8136 KB Output is correct
35 Correct 270 ms 8224 KB Output is correct
36 Correct 264 ms 8252 KB Output is correct
37 Correct 269 ms 8176 KB Output is correct
38 Correct 257 ms 8388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1364 KB Output is correct
2 Correct 4 ms 1364 KB Output is correct
3 Correct 5 ms 1404 KB Output is correct
4 Correct 5 ms 1364 KB Output is correct
5 Correct 5 ms 1364 KB Output is correct
6 Correct 7 ms 1356 KB Output is correct
7 Correct 8 ms 1352 KB Output is correct
8 Correct 6 ms 1364 KB Output is correct
9 Correct 7 ms 1364 KB Output is correct
10 Correct 7 ms 1452 KB Output is correct
11 Correct 8 ms 1364 KB Output is correct
12 Correct 6 ms 1424 KB Output is correct
13 Correct 6 ms 1364 KB Output is correct
14 Correct 8 ms 1364 KB Output is correct
15 Correct 6 ms 1364 KB Output is correct
16 Correct 4 ms 1236 KB Output is correct
17 Correct 4 ms 1236 KB Output is correct
18 Correct 3 ms 1236 KB Output is correct
19 Correct 3 ms 1236 KB Output is correct
20 Correct 4 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 263 ms 8192 KB Output is correct
2 Correct 256 ms 8172 KB Output is correct
3 Correct 283 ms 8268 KB Output is correct
4 Correct 300 ms 8180 KB Output is correct
5 Correct 253 ms 8204 KB Output is correct
6 Correct 164 ms 8320 KB Output is correct
7 Correct 156 ms 8012 KB Output is correct
8 Correct 161 ms 8084 KB Output is correct
9 Correct 171 ms 8260 KB Output is correct
10 Correct 161 ms 8276 KB Output is correct
11 Correct 160 ms 7964 KB Output is correct
12 Correct 165 ms 8128 KB Output is correct
13 Correct 156 ms 7980 KB Output is correct
14 Correct 153 ms 8292 KB Output is correct
15 Correct 181 ms 8120 KB Output is correct
16 Correct 56 ms 5712 KB Output is correct
17 Correct 56 ms 5716 KB Output is correct
18 Correct 69 ms 5752 KB Output is correct
19 Correct 58 ms 5780 KB Output is correct
20 Correct 56 ms 5820 KB Output is correct
21 Correct 448 ms 8268 KB Output is correct
22 Correct 445 ms 8300 KB Output is correct
23 Correct 431 ms 8152 KB Output is correct
24 Correct 441 ms 8228 KB Output is correct
25 Correct 478 ms 8196 KB Output is correct
26 Correct 617 ms 8184 KB Output is correct
27 Correct 665 ms 8208 KB Output is correct
28 Correct 630 ms 8284 KB Output is correct
29 Correct 614 ms 8228 KB Output is correct
30 Correct 177 ms 8196 KB Output is correct
31 Correct 172 ms 7928 KB Output is correct
32 Correct 157 ms 8012 KB Output is correct
33 Correct 159 ms 8056 KB Output is correct
34 Correct 184 ms 8136 KB Output is correct
35 Correct 270 ms 8224 KB Output is correct
36 Correct 264 ms 8252 KB Output is correct
37 Correct 269 ms 8176 KB Output is correct
38 Correct 257 ms 8388 KB Output is correct
39 Correct 5 ms 1364 KB Output is correct
40 Correct 4 ms 1364 KB Output is correct
41 Correct 5 ms 1404 KB Output is correct
42 Correct 5 ms 1364 KB Output is correct
43 Correct 5 ms 1364 KB Output is correct
44 Correct 7 ms 1356 KB Output is correct
45 Correct 8 ms 1352 KB Output is correct
46 Correct 6 ms 1364 KB Output is correct
47 Correct 7 ms 1364 KB Output is correct
48 Correct 7 ms 1452 KB Output is correct
49 Correct 8 ms 1364 KB Output is correct
50 Correct 6 ms 1424 KB Output is correct
51 Correct 6 ms 1364 KB Output is correct
52 Correct 8 ms 1364 KB Output is correct
53 Correct 6 ms 1364 KB Output is correct
54 Correct 4 ms 1236 KB Output is correct
55 Correct 4 ms 1236 KB Output is correct
56 Correct 3 ms 1236 KB Output is correct
57 Correct 3 ms 1236 KB Output is correct
58 Correct 4 ms 1236 KB Output is correct
59 Correct 495 ms 8148 KB Output is correct
60 Correct 478 ms 8300 KB Output is correct
61 Correct 463 ms 8376 KB Output is correct
62 Correct 509 ms 8316 KB Output is correct
63 Correct 494 ms 8200 KB Output is correct
64 Correct 730 ms 8292 KB Output is correct
65 Correct 710 ms 8360 KB Output is correct
66 Correct 719 ms 8276 KB Output is correct
67 Correct 711 ms 8260 KB Output is correct
68 Correct 719 ms 8168 KB Output is correct
69 Correct 545 ms 8216 KB Output is correct
70 Correct 551 ms 8212 KB Output is correct
71 Correct 578 ms 8228 KB Output is correct
72 Correct 553 ms 8280 KB Output is correct
73 Correct 550 ms 8352 KB Output is correct
74 Correct 107 ms 5756 KB Output is correct
75 Correct 116 ms 5748 KB Output is correct
76 Correct 100 ms 5744 KB Output is correct
77 Correct 101 ms 5680 KB Output is correct
78 Correct 99 ms 5728 KB Output is correct