Submission #549774

#TimeUsernameProblemLanguageResultExecution timeMemory
549774krit3379Boat (APIO16_boat)C++17
100 / 100
1210 ms4452 KiB
#include<bits/stdc++.h> using namespace std; #define N 505 long long dp[N][2*N],a[N],b[N],len[2*N],inv[N],cnt,ch,mod=1e9+7; vector<long long> v; int main(){ int n,i,j,k; scanf("%d",&n); inv[1]=1; for(i=2;i<N;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod; for(i=1;i<=n;i++)scanf("%lld %lld",&a[i],&b[i]),v.push_back(a[i]),v.push_back(b[i]+1); sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end())-v.begin()); for(i=1;i<=n;i++){ a[i]=upper_bound(v.begin(),v.end(),a[i])-v.begin(); b[i]=upper_bound(v.begin(),v.end(),b[i])-v.begin(); } for(i=1;i<v.size();i++)len[i]=v[i]-v[i-1]; for(i=0;i<v.size();i++)dp[0][i]=1; for(i=1;i<=n;i++){ for(j=a[i];j<=b[i];j++){ dp[i][j]=len[j]*dp[i-1][j-1]%mod; cnt=1,ch=len[j]-1; for(k=i-1;k>0;k--){ if(a[k]<=j&&j<=b[k]){ cnt++; ch=ch*(len[j]+cnt-2)%mod*inv[cnt]%mod; if(!ch)break; dp[i][j]=(dp[i][j]+dp[k-1][j-1]*ch)%mod; } } } dp[i][0]=1; for(j=1;j<v.size();j++) dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+mod)%mod; } printf("%lld",(dp[n][v.size()-1]-1+mod)%mod); return 0; }

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:20:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(i=1;i<v.size();i++)len[i]=v[i]-v[i-1];
      |             ~^~~~~~~~~
boat.cpp:21:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(i=0;i<v.size();i++)dp[0][i]=1;
      |             ~^~~~~~~~~
boat.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(j=1;j<v.size();j++)
      |                 ~^~~~~~~~~
boat.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
boat.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     for(i=1;i<=n;i++)scanf("%lld %lld",&a[i],&b[i]),v.push_back(a[i]),v.push_back(b[i]+1);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...