Submission #361298

# Submission time Handle Problem Language Result Execution time Memory
361298 2021-01-29T07:56:32 Z tuank99lhp Boat (APIO16_boat) C++17
100 / 100
910 ms 12396 KB
#include <bits/stdc++.h>

using namespace std;
vector<long long> v;
vector<pair<long long,long long> > V;
int n,l[505],r[505],F[2][2005][505],mod,tinh[505],tinh2[2005][505];
long long lt(long long x,long long y)
{
    if (y==0) return 1;
    long long k=lt(x,y/2);
    if (y%2) return k*k%mod*x%mod;
             return k*k%mod;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for (int i=1;i<=n;++i)
    {
        cin>>l[i]>>r[i];
        v.push_back(l[i]);
        v.push_back(r[i]);
    }
    sort(v.begin(),v.end());
    v.resize(unique(v.begin(),v.end())-v.begin());

    long long ct=1;
    for (int i=0;i<v.size();++i)
    {
        if (ct<v[i]) V.push_back({ct,v[i]-ct});
        ct=v[i]+1;
        V.push_back({v[i],1});
    }

    for (int i=0;i<V.size();++i) F[0][i][0]=1;
    F[1][0][0]=1;

    ct=0;mod=1e9+7;
    for (int i=1;i<=500;++i) tinh[i]=lt(i,mod-2);

    for (int j=0;j<V.size();++j)
     for (int k=1;k<=n;++k) tinh2[j][k]=tinh[k]*(V[j].second-k+1)%mod;

    for (int i=1;i<=n;++i)
    {
        ct=1-ct;
        pair<long long,long long> X={l[i],0LL};
        l[i]=lower_bound(V.begin(),V.end(),X)-V.begin();
        X={r[i],0LL};
        r[i]=lower_bound(V.begin(),V.end(),X)-V.begin();
        for (int j=0;j<V.size();++j)
        {
            if (j) F[ct][j][0]=0;

            if (j) for (int k=0;k<=min(1LL*i,V[j-1].second);++k)
            {

                    F[ct][j][0]+=F[ct][j-1][k];
                    if (F[ct][j][0]>=mod) F[ct][j][0]-=mod;

            }

                for (int k=1;k<=min(1LL*i,V[j].second);++k)
                {
                    F[ct][j][k]=F[1-ct][j][k];

if (j>=l[i] && j<=r[i]){
                        long long X=F[1-ct][j][k-1];
                        X=X*tinh2[j][k]%mod;
                        F[ct][j][k]+=X;
                        if (F[ct][j][k]>=mod) F[ct][j][k]-=mod;
}

                }


            }
        }


    long long kq=mod-1;

     for (int k=0;k<=n;++k) {kq=(kq+F[ct][V.size()-1][k]);if (kq>=mod) kq-=mod;}
    cout<<kq;

    return 0;
}

Compilation message

boat.cpp: In function 'long long int lt(long long int, long long int)':
boat.cpp:11:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   11 |     if (y%2) return k*k%mod*x%mod;
      |     ^~
boat.cpp:12:14: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   12 |              return k*k%mod;
      |              ^~~~~~
boat.cpp: In function 'int main()':
boat.cpp:28:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i=0;i<v.size();++i)
      |                  ~^~~~~~~~~
boat.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int i=0;i<V.size();++i) F[0][i][0]=1;
      |                  ~^~~~~~~~~
boat.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int j=0;j<V.size();++j)
      |                  ~^~~~~~~~~
boat.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for (int j=0;j<V.size();++j)
      |                      ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 162 ms 6508 KB Output is correct
2 Correct 162 ms 6380 KB Output is correct
3 Correct 183 ms 6508 KB Output is correct
4 Correct 167 ms 6508 KB Output is correct
5 Correct 169 ms 6380 KB Output is correct
6 Correct 162 ms 6508 KB Output is correct
7 Correct 166 ms 6380 KB Output is correct
8 Correct 167 ms 6380 KB Output is correct
9 Correct 164 ms 6380 KB Output is correct
10 Correct 167 ms 6508 KB Output is correct
11 Correct 165 ms 6380 KB Output is correct
12 Correct 168 ms 6380 KB Output is correct
13 Correct 166 ms 6380 KB Output is correct
14 Correct 167 ms 6508 KB Output is correct
15 Correct 162 ms 6380 KB Output is correct
16 Correct 29 ms 1388 KB Output is correct
17 Correct 38 ms 1516 KB Output is correct
18 Correct 30 ms 1516 KB Output is correct
19 Correct 32 ms 1516 KB Output is correct
20 Correct 32 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 6508 KB Output is correct
2 Correct 162 ms 6380 KB Output is correct
3 Correct 183 ms 6508 KB Output is correct
4 Correct 167 ms 6508 KB Output is correct
5 Correct 169 ms 6380 KB Output is correct
6 Correct 162 ms 6508 KB Output is correct
7 Correct 166 ms 6380 KB Output is correct
8 Correct 167 ms 6380 KB Output is correct
9 Correct 164 ms 6380 KB Output is correct
10 Correct 167 ms 6508 KB Output is correct
11 Correct 165 ms 6380 KB Output is correct
12 Correct 168 ms 6380 KB Output is correct
13 Correct 166 ms 6380 KB Output is correct
14 Correct 167 ms 6508 KB Output is correct
15 Correct 162 ms 6380 KB Output is correct
16 Correct 29 ms 1388 KB Output is correct
17 Correct 38 ms 1516 KB Output is correct
18 Correct 30 ms 1516 KB Output is correct
19 Correct 32 ms 1516 KB Output is correct
20 Correct 32 ms 1516 KB Output is correct
21 Correct 35 ms 10348 KB Output is correct
22 Correct 37 ms 10564 KB Output is correct
23 Correct 39 ms 10220 KB Output is correct
24 Correct 36 ms 10476 KB Output is correct
25 Correct 36 ms 10220 KB Output is correct
26 Correct 31 ms 9708 KB Output is correct
27 Correct 41 ms 9836 KB Output is correct
28 Correct 33 ms 9836 KB Output is correct
29 Correct 31 ms 9836 KB Output is correct
30 Correct 174 ms 11372 KB Output is correct
31 Correct 175 ms 11372 KB Output is correct
32 Correct 181 ms 11500 KB Output is correct
33 Correct 179 ms 11500 KB Output is correct
34 Correct 190 ms 11500 KB Output is correct
35 Correct 164 ms 6508 KB Output is correct
36 Correct 155 ms 6508 KB Output is correct
37 Correct 172 ms 6380 KB Output is correct
38 Correct 156 ms 6508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2796 KB Output is correct
2 Correct 7 ms 2796 KB Output is correct
3 Correct 7 ms 2796 KB Output is correct
4 Correct 7 ms 2796 KB Output is correct
5 Correct 8 ms 2796 KB Output is correct
6 Correct 9 ms 2796 KB Output is correct
7 Correct 9 ms 2796 KB Output is correct
8 Correct 9 ms 2796 KB Output is correct
9 Correct 9 ms 2796 KB Output is correct
10 Correct 9 ms 2796 KB Output is correct
11 Correct 7 ms 2796 KB Output is correct
12 Correct 7 ms 2816 KB Output is correct
13 Correct 7 ms 2796 KB Output is correct
14 Correct 7 ms 2924 KB Output is correct
15 Correct 7 ms 2796 KB Output is correct
16 Correct 3 ms 1388 KB Output is correct
17 Correct 3 ms 1388 KB Output is correct
18 Correct 4 ms 1388 KB Output is correct
19 Correct 4 ms 1388 KB Output is correct
20 Correct 4 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 6508 KB Output is correct
2 Correct 162 ms 6380 KB Output is correct
3 Correct 183 ms 6508 KB Output is correct
4 Correct 167 ms 6508 KB Output is correct
5 Correct 169 ms 6380 KB Output is correct
6 Correct 162 ms 6508 KB Output is correct
7 Correct 166 ms 6380 KB Output is correct
8 Correct 167 ms 6380 KB Output is correct
9 Correct 164 ms 6380 KB Output is correct
10 Correct 167 ms 6508 KB Output is correct
11 Correct 165 ms 6380 KB Output is correct
12 Correct 168 ms 6380 KB Output is correct
13 Correct 166 ms 6380 KB Output is correct
14 Correct 167 ms 6508 KB Output is correct
15 Correct 162 ms 6380 KB Output is correct
16 Correct 29 ms 1388 KB Output is correct
17 Correct 38 ms 1516 KB Output is correct
18 Correct 30 ms 1516 KB Output is correct
19 Correct 32 ms 1516 KB Output is correct
20 Correct 32 ms 1516 KB Output is correct
21 Correct 35 ms 10348 KB Output is correct
22 Correct 37 ms 10564 KB Output is correct
23 Correct 39 ms 10220 KB Output is correct
24 Correct 36 ms 10476 KB Output is correct
25 Correct 36 ms 10220 KB Output is correct
26 Correct 31 ms 9708 KB Output is correct
27 Correct 41 ms 9836 KB Output is correct
28 Correct 33 ms 9836 KB Output is correct
29 Correct 31 ms 9836 KB Output is correct
30 Correct 174 ms 11372 KB Output is correct
31 Correct 175 ms 11372 KB Output is correct
32 Correct 181 ms 11500 KB Output is correct
33 Correct 179 ms 11500 KB Output is correct
34 Correct 190 ms 11500 KB Output is correct
35 Correct 164 ms 6508 KB Output is correct
36 Correct 155 ms 6508 KB Output is correct
37 Correct 172 ms 6380 KB Output is correct
38 Correct 156 ms 6508 KB Output is correct
39 Correct 7 ms 2796 KB Output is correct
40 Correct 7 ms 2796 KB Output is correct
41 Correct 7 ms 2796 KB Output is correct
42 Correct 7 ms 2796 KB Output is correct
43 Correct 8 ms 2796 KB Output is correct
44 Correct 9 ms 2796 KB Output is correct
45 Correct 9 ms 2796 KB Output is correct
46 Correct 9 ms 2796 KB Output is correct
47 Correct 9 ms 2796 KB Output is correct
48 Correct 9 ms 2796 KB Output is correct
49 Correct 7 ms 2796 KB Output is correct
50 Correct 7 ms 2816 KB Output is correct
51 Correct 7 ms 2796 KB Output is correct
52 Correct 7 ms 2924 KB Output is correct
53 Correct 7 ms 2796 KB Output is correct
54 Correct 3 ms 1388 KB Output is correct
55 Correct 3 ms 1388 KB Output is correct
56 Correct 4 ms 1388 KB Output is correct
57 Correct 4 ms 1388 KB Output is correct
58 Correct 4 ms 1388 KB Output is correct
59 Correct 667 ms 12268 KB Output is correct
60 Correct 656 ms 12396 KB Output is correct
61 Correct 644 ms 12336 KB Output is correct
62 Correct 687 ms 12396 KB Output is correct
63 Correct 675 ms 12396 KB Output is correct
64 Correct 899 ms 12336 KB Output is correct
65 Correct 903 ms 12396 KB Output is correct
66 Correct 910 ms 12336 KB Output is correct
67 Correct 893 ms 12396 KB Output is correct
68 Correct 890 ms 12396 KB Output is correct
69 Correct 618 ms 12268 KB Output is correct
70 Correct 613 ms 12268 KB Output is correct
71 Correct 619 ms 12336 KB Output is correct
72 Correct 633 ms 12396 KB Output is correct
73 Correct 636 ms 12396 KB Output is correct
74 Correct 62 ms 1644 KB Output is correct
75 Correct 70 ms 1644 KB Output is correct
76 Correct 70 ms 1644 KB Output is correct
77 Correct 61 ms 1644 KB Output is correct
78 Correct 62 ms 1644 KB Output is correct