Submission #739459

# Submission time Handle Problem Language Result Execution time Memory
739459 2023-05-10T13:31:11 Z Alihan_8 Boat (APIO16_boat) C++17
0 / 100
26 ms 32220 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define pb push_back
#define ln '\n'
#define int long long

template <class _T>
bool chmin(_T &x, const _T &y){
    bool flag = false;
    if ( x > y ){
        x = y; flag |= true;
    }
    return flag;
}

template <class _T>
bool chmax(_T &x, const _T &y){
    bool flag = false;
    if ( x < y ){
        x = y; flag |= true;
    }
    return flag;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    vector <int> a(n), b(n), pos;
    for ( int i = 0; i < n; i++ ){
        cin >> a[i] >> b[i];
        pos.pb(a[i]); pos.pb(b[i]);
    }
    sort(all(pos));
    pos.resize(unique(all(pos)) - pos.begin());
    auto id = [&](int x){
        return lower_bound(all(pos), x) - pos.begin() + 1;
    };
    const int Mod = 1e9 + 7, N = 1e6 + 1;
    auto add = [&](int &x, const int &y){
        x = (x + y) % Mod;
        if ( x < 0 ) x += Mod;
    };
    vector <int> dp(N), pref(N, 1);
    dp[0] = 1;
    for ( int i = 1; i <= n; i++ ){
        for ( int j = a[i - 1]; j <= b[i - 1]; j++ ){
            add(dp[j], pref[j - 1]);
        }
        for ( int j = 1; j < N; j++ ){
            pref[j] = (pref[j - 1] + dp[j]) % Mod;
        }
    }
    int res = pref.back();
    add(res, -1);
    cout << res;

    cout << '\n';
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:40:10: warning: variable 'id' set but not used [-Wunused-but-set-variable]
   40 |     auto id = [&](int x){
      |          ^~
# Verdict Execution time Memory Grader output
1 Runtime error 21 ms 32188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 21 ms 32188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 32220 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 21 ms 32188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -