Submission #549738

#TimeUsernameProblemLanguageResultExecution timeMemory
549738krit3379Boat (APIO16_boat)C++17
0 / 100
836 ms524288 KiB
#include<bits/stdc++.h> using namespace std; #define N 505 long long dp[N][N][N],a[N],b[N],l[2*N],r[2*N],ans,mod=1e9+7; vector<long long> v; // num -> at i-th scholl -> with up_val int main(){ int n,i,j,k; scanf("%d",&n); for(i=1;i<=n;i++)scanf("%lld %lld",&a[i],&b[i]),v.push_back(a[i]),v.push_back(b[i]); v.push_back(-1); sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end())-v.begin()); v.push_back(v.back()+1); for(i=1;i<=n;i++){ l[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin(); r[i]=lower_bound(v.begin(),v.end(),b[i])-v.begin(); } for(i=0;i<=n;i++)for(j=0;j<=n;j++)dp[0][i][j]=1; for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ for(k=1;k<v.size();k++){ if(l[j]<=k&&k<=r[j])dp[i][j][k]=(dp[i][j][k]+dp[i-1][j-1][k-1]*(v[k+1]-v[k]))%mod; dp[i][j][k]=(dp[i][j][k]+dp[i][j][k-1]+dp[i][j-1][k]-dp[i][j-1][k-1]+mod)%mod; } } ans=(ans+dp[i][n][v.size()-1])%mod; } printf("%lld",ans); return 0; }

Compilation message (stderr)

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