Submission #23038

#TimeUsernameProblemLanguageResultExecution timeMemory
23038ngkan146Boat (APIO16_boat)C++98
9 / 100
3 ms2420 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = (ll) 1e9+7;
ll n, a[505], b[505];
vector <ll> mjk;
ll dp[50005];
ll len(ll l1,ll r1,ll l2,ll r2){
   return max(0ll, min(r1,r2) - max(l1,l2) + 1);
}
int main(){
   scanf("%lld",&n);
   for(int i=1;i<=n;i++)
      scanf("%lld %lld",&a[i],&b[i]),
      mjk.push_back(a[i]),
      mjk.push_back(b[i]);
   mjk.push_back(0ll);
   mjk.push_back((ll)1e9+1);
   sort(mjk.begin(),mjk.end());
   mjk.resize(unique(mjk.begin(),mjk.end()) - mjk.begin());
   dp[0] = 1;
   for(int i=1;i<=n;i++){
      ll cnt = 0;
      for(int j=0;j<mjk.size()-1;j++){
         ll tmp = (cnt + dp[j]) % mod;
         dp[j] = (dp[j] + len(mjk[j], mjk[j+1]-1, a[i], b[i]) * cnt) % mod;
         cnt = tmp;
      }
   }
   ll ans = 0;
   for(int i=1;i<mjk.size()-1;i++)
      ans = (ans + dp[i]) % mod;
   cout << ans;
}

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int j=0;j<mjk.size()-1;j++){
                    ^
boat.cpp:31:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=1;i<mjk.size()-1;i++)
                 ^
boat.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld",&n);
                    ^
boat.cpp:16:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       mjk.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...