Submission #139553

#TimeUsernameProblemLanguageResultExecution timeMemory
139553meatrowBoat (APIO16_boat)C++17
9 / 100
4 ms504 KiB
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;

const int N = 1500;

int dp[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    set<int> pnts;
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
        pnts.insert(a[i].first);
        pnts.insert(a[i].first - 1);
        pnts.insert(a[i].second);
    }
    size_t m = pnts.size();
    vector<int> b(m);
    auto it = pnts.begin();
    for (int& i : b) {
        i = *(it++);
    }
    fill(dp, dp + m, 1);
    for (int i = 0; i < n; i++) {
        int len = a[i].second - a[i].first;
        int a0 = 0;
        ll d = 0;
        for (int j = 0; j < m; j++) {
            int pos = b[j];
            if (pos == a[i].first - 1) {
                a0 = dp[j];
            }
            if (pos == a[i].first) {
                d = dp[j];
            }
            if (pos >= a[i].first ) {
                dp[j] += a0 + d * min(pos - a[i].first, len);
                dp[j] %= mod;
            }
        }
    }
    cout << dp[m - 1] - 1;
    return 0;
}

Compilation message (stderr)

boat.cpp: In function 'int main()':
boat.cpp:42:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < m; j++) {
                         ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...