Submission #1106717

# Submission time Handle Problem Language Result Execution time Memory
1106717 2024-10-31T01:42:32 Z 12345678 Boat (APIO16_boat) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int nx=505, mod=1e9+7;
ll n, a[nx], b[nx], dp[nx][2*nx], qs[nx][2*nx], sz[2*nx], t, pv, ncr[nx][nx], select[2*nx][nx], l[nx], r[nx];
map<ll, ll> mp;

ll invmod(ll a, ll x)
{
    if (x==0) return 1;
    auto tmp=invmod(a, x/2);
    tmp=(tmp*tmp)%mod;
    if (x%2) return (tmp*a)%mod;
    else return tmp;
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    mp[0]=0;
    for (int i=1; i<=n; i++) cin>>a[i]>>b[i], mp[--a[i]]=0, mp[b[i]]=0;
    for (auto &[x, y]:mp) y=t, sz[t]=x-pv, pv=x, t++;
    for (int i=1; i<=n; i++) l[i]=mp[a[i]], r[i]=mp[b[i]];
    ncr[0][0]=1;
    for (int i=1; i<=n; i++)
    {
        for (int j=0; j<=i; j++)
        {
            ncr[i][j]=ncr[i-1][j];
            if (j>0) ncr[i][j]=(ncr[i][j]+ncr[i-1][j-1])%mod;
        }
    }
    for (int i=1; i<t; i++)
    {
        ll tmp=1;
        select[i][0]=tmp;
        for (int j=1; j<=min(sz[i], n); j++) tmp=(((tmp*(sz[i]-j+1))%mod)*invmod(j, mod-2))%mod, select[i][j]=tmp;
    }
    for (int i=1; i<=n; i++)
    {
        //cout<<"l "<<i<<' '<<l[i]<<' '<<r[i]<<'\n';
        for (int j=1; j<t; j++)
        {
            if (l[i]<j&&j<=r[i])
            {
                dp[i][j]=qs[i-1][j-1]+1;
                ll cnt=1;
                for (int k=i-1; k>=1; k--)
                {
                    if (l[k]<j&&j<=r[k]) cnt++;
                    if (cnt>=2)
                    {
                        ll sm=0;
                        for (int tmp=0; tmp<=cnt-2; tmp++) sm=(sm+select[j][cnt]*ncr[cnt-2][tmp])%mod;
                        dp[i][j]=(dp[i][j]+sm*(qs[k-1][j-1]+1))%mod;
                    }
                }
            }
            //cout<<"dp "<<i<<' '<<j<<' '<<dp[i][j]<<'\n';
            qs[i][j]=((dp[i][j]+qs[i-1][j]+qs[i][j-1]-qs[i-1][j-1])%mod+mod)%mod;
        }
    }
    cout<<qs[n][t-1];
}

Compilation message

boat.cpp:8:94: error: 'long long int select [1010][505]' redeclared as different kind of entity
    8 | ll n, a[nx], b[nx], dp[nx][2*nx], qs[nx][2*nx], sz[2*nx], t, pv, ncr[nx][nx], select[2*nx][nx], l[nx], r[nx];
      |                                                                                              ^
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:179,
                 from /usr/include/stdlib.h:394,
                 from /usr/include/c++/10/bits/std_abs.h:38,
                 from /usr/include/c++/10/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from boat.cpp:1:
/usr/include/x86_64-linux-gnu/sys/select.h:101:12: note: previous declaration 'int select(int, fd_set*, fd_set*, fd_set*, timeval*)'
  101 | extern int select (int __nfds, fd_set *__restrict __readfds,
      |            ^~~~~~
boat.cpp: In function 'int main()':
boat.cpp:40:17: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   40 |         select[i][0]=tmp;
      |                 ^
boat.cpp:40:20: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   40 |         select[i][0]=tmp;
      |                    ^
boat.cpp:40:21: error: assignment of read-only location '*(select + ((sizetype)i))'
   40 |         select[i][0]=tmp;
      |         ~~~~~~~~~~~~^~~~
boat.cpp:41:106: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   41 |         for (int j=1; j<=min(sz[i], n); j++) tmp=(((tmp*(sz[i]-j+1))%mod)*invmod(j, mod-2))%mod, select[i][j]=tmp;
      |                                                                                                          ^
boat.cpp:41:109: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   41 |         for (int j=1; j<=min(sz[i], n); j++) tmp=(((tmp*(sz[i]-j+1))%mod)*invmod(j, mod-2))%mod, select[i][j]=tmp;
      |                                                                                                             ^
boat.cpp:41:110: error: assignment of read-only location '*(select + (((sizetype)i) + ((sizetype)j)))'
   41 |         for (int j=1; j<=min(sz[i], n); j++) tmp=(((tmp*(sz[i]-j+1))%mod)*invmod(j, mod-2))%mod, select[i][j]=tmp;
      |                                                                                                  ~~~~~~~~~~~~^~~~
boat.cpp:58:75: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |                         for (int tmp=0; tmp<=cnt-2; tmp++) sm=(sm+select[j][cnt]*ncr[cnt-2][tmp])%mod;
      |                                                                           ^
boat.cpp:58:80: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |                         for (int tmp=0; tmp<=cnt-2; tmp++) sm=(sm+select[j][cnt]*ncr[cnt-2][tmp])%mod;
      |                                                                                ^
boat.cpp:58:81: error: invalid operands of types 'int(int, fd_set*, fd_set*, fd_set*, timeval*)' and 'long long int' to binary 'operator*'
   58 |                         for (int tmp=0; tmp<=cnt-2; tmp++) sm=(sm+select[j][cnt]*ncr[cnt-2][tmp])%mod;
      |                                                                   ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
      |                                                                                |               |
      |                                                                                |               long long int
      |                                                                                int(int, fd_set*, fd_set*, fd_set*, timeval*)