Submission #361306

# Submission time Handle Problem Language Result Execution time Memory
361306 2021-01-29T08:36:17 Z tuank99lhp Boat (APIO16_boat) C++17
100 / 100
793 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()
{
  //  freopen("a.inp","r",stdin);
   // freopen("a.out","w",stdout);
    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)
            {
                    if (F[ct][j-1][k]==0 && F[ct][j-1][k+1]==0) break;

                    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)
                {
                    if (F[1-ct][j][k-1]==0 && F[1-ct][j][k]==0) break;
                    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:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (int i=0;i<v.size();++i)
      |                  ~^~~~~~~~~
boat.cpp:37: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]
   37 |     for (int i=0;i<V.size();++i) F[0][i][0]=1;
      |                  ~^~~~~~~~~
boat.cpp:43: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]
   43 |     for (int j=0;j<V.size();++j)
      |                  ~^~~~~~~~~
boat.cpp:53: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]
   53 |         for (int j=0;j<V.size();++j)
      |                      ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6380 KB Output is correct
2 Correct 12 ms 6380 KB Output is correct
3 Correct 10 ms 6400 KB Output is correct
4 Correct 10 ms 6380 KB Output is correct
5 Correct 10 ms 6380 KB Output is correct
6 Correct 9 ms 6380 KB Output is correct
7 Correct 9 ms 6380 KB Output is correct
8 Correct 9 ms 6380 KB Output is correct
9 Correct 12 ms 6380 KB Output is correct
10 Correct 9 ms 6400 KB Output is correct
11 Correct 9 ms 6380 KB Output is correct
12 Correct 9 ms 6380 KB Output is correct
13 Correct 12 ms 6380 KB Output is correct
14 Correct 9 ms 6380 KB Output is correct
15 Correct 9 ms 6380 KB Output is correct
16 Correct 2 ms 1388 KB Output is correct
17 Correct 2 ms 1516 KB Output is correct
18 Correct 2 ms 1388 KB Output is correct
19 Correct 2 ms 1516 KB Output is correct
20 Correct 3 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6380 KB Output is correct
2 Correct 12 ms 6380 KB Output is correct
3 Correct 10 ms 6400 KB Output is correct
4 Correct 10 ms 6380 KB Output is correct
5 Correct 10 ms 6380 KB Output is correct
6 Correct 9 ms 6380 KB Output is correct
7 Correct 9 ms 6380 KB Output is correct
8 Correct 9 ms 6380 KB Output is correct
9 Correct 12 ms 6380 KB Output is correct
10 Correct 9 ms 6400 KB Output is correct
11 Correct 9 ms 6380 KB Output is correct
12 Correct 9 ms 6380 KB Output is correct
13 Correct 12 ms 6380 KB Output is correct
14 Correct 9 ms 6380 KB Output is correct
15 Correct 9 ms 6380 KB Output is correct
16 Correct 2 ms 1388 KB Output is correct
17 Correct 2 ms 1516 KB Output is correct
18 Correct 2 ms 1388 KB Output is correct
19 Correct 2 ms 1516 KB Output is correct
20 Correct 3 ms 1516 KB Output is correct
21 Correct 41 ms 10348 KB Output is correct
22 Correct 39 ms 10348 KB Output is correct
23 Correct 39 ms 10220 KB Output is correct
24 Correct 44 ms 10348 KB Output is correct
25 Correct 39 ms 10092 KB Output is correct
26 Correct 31 ms 9708 KB Output is correct
27 Correct 35 ms 9836 KB Output is correct
28 Correct 38 ms 9836 KB Output is correct
29 Correct 35 ms 9836 KB Output is correct
30 Correct 24 ms 11372 KB Output is correct
31 Correct 24 ms 11372 KB Output is correct
32 Correct 28 ms 11628 KB Output is correct
33 Correct 24 ms 11372 KB Output is correct
34 Correct 24 ms 11392 KB Output is correct
35 Correct 10 ms 6380 KB Output is correct
36 Correct 10 ms 6380 KB Output is correct
37 Correct 10 ms 6380 KB Output is correct
38 Correct 10 ms 6252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2796 KB Output is correct
2 Correct 6 ms 2796 KB Output is correct
3 Correct 6 ms 2796 KB Output is correct
4 Correct 5 ms 2796 KB Output is correct
5 Correct 6 ms 2796 KB Output is correct
6 Correct 8 ms 2796 KB Output is correct
7 Correct 8 ms 2796 KB Output is correct
8 Correct 8 ms 2796 KB Output is correct
9 Correct 8 ms 2796 KB Output is correct
10 Correct 8 ms 2796 KB Output is correct
11 Correct 6 ms 2796 KB Output is correct
12 Correct 6 ms 2796 KB Output is correct
13 Correct 6 ms 2796 KB Output is correct
14 Correct 6 ms 2796 KB Output is correct
15 Correct 6 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 3 ms 1388 KB Output is correct
20 Correct 3 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6380 KB Output is correct
2 Correct 12 ms 6380 KB Output is correct
3 Correct 10 ms 6400 KB Output is correct
4 Correct 10 ms 6380 KB Output is correct
5 Correct 10 ms 6380 KB Output is correct
6 Correct 9 ms 6380 KB Output is correct
7 Correct 9 ms 6380 KB Output is correct
8 Correct 9 ms 6380 KB Output is correct
9 Correct 12 ms 6380 KB Output is correct
10 Correct 9 ms 6400 KB Output is correct
11 Correct 9 ms 6380 KB Output is correct
12 Correct 9 ms 6380 KB Output is correct
13 Correct 12 ms 6380 KB Output is correct
14 Correct 9 ms 6380 KB Output is correct
15 Correct 9 ms 6380 KB Output is correct
16 Correct 2 ms 1388 KB Output is correct
17 Correct 2 ms 1516 KB Output is correct
18 Correct 2 ms 1388 KB Output is correct
19 Correct 2 ms 1516 KB Output is correct
20 Correct 3 ms 1516 KB Output is correct
21 Correct 41 ms 10348 KB Output is correct
22 Correct 39 ms 10348 KB Output is correct
23 Correct 39 ms 10220 KB Output is correct
24 Correct 44 ms 10348 KB Output is correct
25 Correct 39 ms 10092 KB Output is correct
26 Correct 31 ms 9708 KB Output is correct
27 Correct 35 ms 9836 KB Output is correct
28 Correct 38 ms 9836 KB Output is correct
29 Correct 35 ms 9836 KB Output is correct
30 Correct 24 ms 11372 KB Output is correct
31 Correct 24 ms 11372 KB Output is correct
32 Correct 28 ms 11628 KB Output is correct
33 Correct 24 ms 11372 KB Output is correct
34 Correct 24 ms 11392 KB Output is correct
35 Correct 10 ms 6380 KB Output is correct
36 Correct 10 ms 6380 KB Output is correct
37 Correct 10 ms 6380 KB Output is correct
38 Correct 10 ms 6252 KB Output is correct
39 Correct 5 ms 2796 KB Output is correct
40 Correct 6 ms 2796 KB Output is correct
41 Correct 6 ms 2796 KB Output is correct
42 Correct 5 ms 2796 KB Output is correct
43 Correct 6 ms 2796 KB Output is correct
44 Correct 8 ms 2796 KB Output is correct
45 Correct 8 ms 2796 KB Output is correct
46 Correct 8 ms 2796 KB Output is correct
47 Correct 8 ms 2796 KB Output is correct
48 Correct 8 ms 2796 KB Output is correct
49 Correct 6 ms 2796 KB Output is correct
50 Correct 6 ms 2796 KB Output is correct
51 Correct 6 ms 2796 KB Output is correct
52 Correct 6 ms 2796 KB Output is correct
53 Correct 6 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 3 ms 1388 KB Output is correct
58 Correct 3 ms 1388 KB Output is correct
59 Correct 455 ms 12268 KB Output is correct
60 Correct 419 ms 12396 KB Output is correct
61 Correct 407 ms 12396 KB Output is correct
62 Correct 449 ms 12268 KB Output is correct
63 Correct 433 ms 12396 KB Output is correct
64 Correct 784 ms 12396 KB Output is correct
65 Correct 779 ms 12396 KB Output is correct
66 Correct 787 ms 12396 KB Output is correct
67 Correct 769 ms 12324 KB Output is correct
68 Correct 793 ms 12396 KB Output is correct
69 Correct 450 ms 12396 KB Output is correct
70 Correct 444 ms 12396 KB Output is correct
71 Correct 471 ms 12396 KB Output is correct
72 Correct 477 ms 12324 KB Output is correct
73 Correct 466 ms 12324 KB Output is correct
74 Correct 42 ms 1636 KB Output is correct
75 Correct 41 ms 1516 KB Output is correct
76 Correct 42 ms 1516 KB Output is correct
77 Correct 42 ms 1516 KB Output is correct
78 Correct 43 ms 1516 KB Output is correct