Submission #403978

# Submission time Handle Problem Language Result Execution time Memory
403978 2021-05-13T16:09:46 Z sad Boat (APIO16_boat) C++14
0 / 100
2000 ms 307940 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
int dp[2][1000090],a[503],b[503];
int n;
const int mod=1e9+7;
vector<int>v;
set<int>s;
int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;v.pb(0);
    for(int i=1; i<=n; i++)
    {
        cin>>a[i]>>b[i];
        for(int j=a[i]; j<=b[i]; j++)
        {
            s.insert(j);
        }
    }
    while(s.size()>0)
    {
        v.pb(*s.begin());
        s.erase(s.begin());
    }
    for(int i=0;i<v.size();i++)dp[0][i]=1;
    for(int i=0;i<n+1;i++)dp[i][0]=1;
    for(int i=1;i<n+1;i++)
    {int g=i%2;
            int gg=(i+1)%2;
        for(int j=1; j<v.size(); j++)
        {int u=0;
            u+=dp[gg][j];
            u%=mod;int x=i,y=j;
            if(a[i]<=v[j]&&b[i]>=v[j])
            {
                u+=dp[gg][y-1];
                u%=mod;
                u+=dp[g][y-1];
                u%=mod;
                u-=dp[gg][y-1];
                u+=mod;
                u%=mod;
            }
            else
            {
                u+=dp[g][y-1];
                u%=mod;
                u-=dp[gg][y-1];
                u+=mod;
                u%=mod;
            }
        dp[g][j]=u;u=0;
        }
        for(int j=0;j<v.size()+1;j++)dp[gg][j]=0;
        dp[gg][0]=1;
    }
    int w=n%2;
    cout<<dp[w][v.size()-1]-1;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i=0;i<v.size();i++)dp[0][i]=1;
      |                 ~^~~~~~~~~
boat.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for(int j=1; j<v.size(); j++)
      |                      ~^~~~~~~~~
boat.cpp:36:24: warning: unused variable 'x' [-Wunused-variable]
   36 |             u%=mod;int x=i,y=j;
      |                        ^
boat.cpp:57:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for(int j=0;j<v.size()+1;j++)dp[gg][j]=0;
      |                     ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 2099 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2099 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2114 ms 307940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2099 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -