Submission #549738

# Submission time Handle Problem Language Result Execution time Memory
549738 2022-04-16T11:37:26 Z krit3379 Boat (APIO16_boat) C++17
0 / 100
836 ms 524288 KB
#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

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 time Memory Grader output
1 Runtime error 836 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 836 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 40620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 836 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -