Submission #730286

# Submission time Handle Problem Language Result Execution time Memory
730286 2023-04-25T15:03:35 Z abcvuitunggio Boat (APIO16_boat) C++17
100 / 100
920 ms 12268 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
int dp[2][1010][501],c[1001][501],n,a[501],b[501],l[1001],r[1001],id,f[501];
vector <pair <int, int>> v;
int pw(int a, int b){
    if (!b)
        return 1;
    int t=pw(a,b>>1);
    t=(t*t)%mod;
    return (b&1?(t*a)%mod:t);
}
int32_t main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n;
    f[0]=1;
    for (int i=1;i<=n;i++){
        cin >> a[i] >> b[i];
        v.push_back({a[i],0});
        v.push_back({b[i],1});
        f[i]=f[i-1]*i%mod;
    }
    for (int i=1;i<=n;i++)
        f[i]=pw(f[i],mod-2);
    sort(v.begin(),v.end());
    for (int i=0;i<v.size()-1;i++){
        id++;
        l[id]=v[i].first+v[i].second;
        r[id]=v[i+1].first-1+v[i+1].second;
        c[id][0]=1;
        for (int j=1;j<=n;j++)
            c[id][j]=c[id][j-1]*(r[id]-l[id]-j+2)%mod;
        for (int j=2;j<=n;j++)
            c[id][j]=c[id][j]*f[j]%mod;
    }
    for (int i=0;i<2;i++)
        for (int k=0;k<=n;k++)
            dp[i][id+1][k]=1;
    for (int j=1;j<=id;j++)
        for (int k=0;k<=n;k++)
            dp[n&1^1][j][k]=(j>id?1:c[j][k]);
    for (int i=n;i>=1;i--)
        for (int j=id;j;j--)
            for (int k=0;k<=n;k++){
                if (k>r[j]-l[j]+1){
                    dp[i&1][j][k]=0;
                    continue;
                }
                dp[i&1][j][k]=dp[i&1^1][j][k]+(dp[i&1][j+1][0]-dp[i&1^1][j+1][0])*c[j][k]+(a[i]<=l[j]&&r[j]<=b[i])*dp[i&1^1][j][k+1];
                dp[i&1][j][k]%=mod;
            }
    dp[1][1][0]=(dp[1][1][0]-1)%mod;
    cout << (dp[1][1][0]+mod)%mod;
}

Compilation message

boat.cpp: In function 'int32_t main()':
boat.cpp:27:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i=0;i<v.size()-1;i++){
      |                  ~^~~~~~~~~~~
boat.cpp:42:17: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   42 |             dp[n&1^1][j][k]=(j>id?1:c[j][k]);
      |                ~^~
boat.cpp:50:35: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   50 |                 dp[i&1][j][k]=dp[i&1^1][j][k]+(dp[i&1][j+1][0]-dp[i&1^1][j+1][0])*c[j][k]+(a[i]<=l[j]&&r[j]<=b[i])*dp[i&1^1][j][k+1];
      |                                  ~^~
boat.cpp:50:68: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   50 |                 dp[i&1][j][k]=dp[i&1^1][j][k]+(dp[i&1][j+1][0]-dp[i&1^1][j+1][0])*c[j][k]+(a[i]<=l[j]&&r[j]<=b[i])*dp[i&1^1][j][k+1];
      |                                                                   ~^~
boat.cpp:50:120: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   50 |                 dp[i&1][j][k]=dp[i&1^1][j][k]+(dp[i&1][j+1][0]-dp[i&1^1][j+1][0])*c[j][k]+(a[i]<=l[j]&&r[j]<=b[i])*dp[i&1^1][j][k+1];
      |                                                                                                                       ~^~
# Verdict Execution time Memory Grader output
1 Correct 516 ms 12064 KB Output is correct
2 Correct 570 ms 12096 KB Output is correct
3 Correct 530 ms 12148 KB Output is correct
4 Correct 531 ms 12152 KB Output is correct
5 Correct 529 ms 12260 KB Output is correct
6 Correct 523 ms 12116 KB Output is correct
7 Correct 538 ms 12132 KB Output is correct
8 Correct 623 ms 12132 KB Output is correct
9 Correct 616 ms 12132 KB Output is correct
10 Correct 619 ms 12136 KB Output is correct
11 Correct 532 ms 12268 KB Output is correct
12 Correct 556 ms 12140 KB Output is correct
13 Correct 625 ms 12136 KB Output is correct
14 Correct 584 ms 12116 KB Output is correct
15 Correct 546 ms 12116 KB Output is correct
16 Correct 290 ms 12148 KB Output is correct
17 Correct 310 ms 12136 KB Output is correct
18 Correct 282 ms 12116 KB Output is correct
19 Correct 284 ms 12116 KB Output is correct
20 Correct 288 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 516 ms 12064 KB Output is correct
2 Correct 570 ms 12096 KB Output is correct
3 Correct 530 ms 12148 KB Output is correct
4 Correct 531 ms 12152 KB Output is correct
5 Correct 529 ms 12260 KB Output is correct
6 Correct 523 ms 12116 KB Output is correct
7 Correct 538 ms 12132 KB Output is correct
8 Correct 623 ms 12132 KB Output is correct
9 Correct 616 ms 12132 KB Output is correct
10 Correct 619 ms 12136 KB Output is correct
11 Correct 532 ms 12268 KB Output is correct
12 Correct 556 ms 12140 KB Output is correct
13 Correct 625 ms 12136 KB Output is correct
14 Correct 584 ms 12116 KB Output is correct
15 Correct 546 ms 12116 KB Output is correct
16 Correct 290 ms 12148 KB Output is correct
17 Correct 310 ms 12136 KB Output is correct
18 Correct 282 ms 12116 KB Output is correct
19 Correct 284 ms 12116 KB Output is correct
20 Correct 288 ms 12116 KB Output is correct
21 Correct 317 ms 12136 KB Output is correct
22 Correct 284 ms 12148 KB Output is correct
23 Correct 240 ms 12116 KB Output is correct
24 Correct 272 ms 12132 KB Output is correct
25 Correct 260 ms 12236 KB Output is correct
26 Correct 243 ms 12136 KB Output is correct
27 Correct 259 ms 12116 KB Output is correct
28 Correct 243 ms 12140 KB Output is correct
29 Correct 247 ms 12132 KB Output is correct
30 Correct 526 ms 12136 KB Output is correct
31 Correct 595 ms 12132 KB Output is correct
32 Correct 563 ms 12132 KB Output is correct
33 Correct 541 ms 12136 KB Output is correct
34 Correct 510 ms 12116 KB Output is correct
35 Correct 539 ms 12148 KB Output is correct
36 Correct 543 ms 12136 KB Output is correct
37 Correct 503 ms 12116 KB Output is correct
38 Correct 506 ms 12136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2644 KB Output is correct
2 Correct 7 ms 2644 KB Output is correct
3 Correct 7 ms 2644 KB Output is correct
4 Correct 8 ms 2644 KB Output is correct
5 Correct 8 ms 2720 KB Output is correct
6 Correct 10 ms 2644 KB Output is correct
7 Correct 7 ms 2644 KB Output is correct
8 Correct 11 ms 2712 KB Output is correct
9 Correct 8 ms 2644 KB Output is correct
10 Correct 7 ms 2644 KB Output is correct
11 Correct 8 ms 2644 KB Output is correct
12 Correct 7 ms 2644 KB Output is correct
13 Correct 7 ms 2644 KB Output is correct
14 Correct 8 ms 2720 KB Output is correct
15 Correct 7 ms 2716 KB Output is correct
16 Correct 5 ms 2716 KB Output is correct
17 Correct 5 ms 2644 KB Output is correct
18 Correct 5 ms 2644 KB Output is correct
19 Correct 5 ms 2644 KB Output is correct
20 Correct 6 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 516 ms 12064 KB Output is correct
2 Correct 570 ms 12096 KB Output is correct
3 Correct 530 ms 12148 KB Output is correct
4 Correct 531 ms 12152 KB Output is correct
5 Correct 529 ms 12260 KB Output is correct
6 Correct 523 ms 12116 KB Output is correct
7 Correct 538 ms 12132 KB Output is correct
8 Correct 623 ms 12132 KB Output is correct
9 Correct 616 ms 12132 KB Output is correct
10 Correct 619 ms 12136 KB Output is correct
11 Correct 532 ms 12268 KB Output is correct
12 Correct 556 ms 12140 KB Output is correct
13 Correct 625 ms 12136 KB Output is correct
14 Correct 584 ms 12116 KB Output is correct
15 Correct 546 ms 12116 KB Output is correct
16 Correct 290 ms 12148 KB Output is correct
17 Correct 310 ms 12136 KB Output is correct
18 Correct 282 ms 12116 KB Output is correct
19 Correct 284 ms 12116 KB Output is correct
20 Correct 288 ms 12116 KB Output is correct
21 Correct 317 ms 12136 KB Output is correct
22 Correct 284 ms 12148 KB Output is correct
23 Correct 240 ms 12116 KB Output is correct
24 Correct 272 ms 12132 KB Output is correct
25 Correct 260 ms 12236 KB Output is correct
26 Correct 243 ms 12136 KB Output is correct
27 Correct 259 ms 12116 KB Output is correct
28 Correct 243 ms 12140 KB Output is correct
29 Correct 247 ms 12132 KB Output is correct
30 Correct 526 ms 12136 KB Output is correct
31 Correct 595 ms 12132 KB Output is correct
32 Correct 563 ms 12132 KB Output is correct
33 Correct 541 ms 12136 KB Output is correct
34 Correct 510 ms 12116 KB Output is correct
35 Correct 539 ms 12148 KB Output is correct
36 Correct 543 ms 12136 KB Output is correct
37 Correct 503 ms 12116 KB Output is correct
38 Correct 506 ms 12136 KB Output is correct
39 Correct 7 ms 2644 KB Output is correct
40 Correct 7 ms 2644 KB Output is correct
41 Correct 7 ms 2644 KB Output is correct
42 Correct 8 ms 2644 KB Output is correct
43 Correct 8 ms 2720 KB Output is correct
44 Correct 10 ms 2644 KB Output is correct
45 Correct 7 ms 2644 KB Output is correct
46 Correct 11 ms 2712 KB Output is correct
47 Correct 8 ms 2644 KB Output is correct
48 Correct 7 ms 2644 KB Output is correct
49 Correct 8 ms 2644 KB Output is correct
50 Correct 7 ms 2644 KB Output is correct
51 Correct 7 ms 2644 KB Output is correct
52 Correct 8 ms 2720 KB Output is correct
53 Correct 7 ms 2716 KB Output is correct
54 Correct 5 ms 2716 KB Output is correct
55 Correct 5 ms 2644 KB Output is correct
56 Correct 5 ms 2644 KB Output is correct
57 Correct 5 ms 2644 KB Output is correct
58 Correct 6 ms 2644 KB Output is correct
59 Correct 857 ms 12144 KB Output is correct
60 Correct 821 ms 12116 KB Output is correct
61 Correct 867 ms 12136 KB Output is correct
62 Correct 886 ms 12132 KB Output is correct
63 Correct 876 ms 12236 KB Output is correct
64 Correct 920 ms 12132 KB Output is correct
65 Correct 875 ms 12136 KB Output is correct
66 Correct 868 ms 12116 KB Output is correct
67 Correct 875 ms 12136 KB Output is correct
68 Correct 888 ms 12148 KB Output is correct
69 Correct 839 ms 12116 KB Output is correct
70 Correct 842 ms 12136 KB Output is correct
71 Correct 892 ms 12140 KB Output is correct
72 Correct 857 ms 12116 KB Output is correct
73 Correct 868 ms 12144 KB Output is correct
74 Correct 330 ms 12104 KB Output is correct
75 Correct 304 ms 12136 KB Output is correct
76 Correct 340 ms 12136 KB Output is correct
77 Correct 319 ms 12236 KB Output is correct
78 Correct 307 ms 12136 KB Output is correct