Submission #956634

#TimeUsernameProblemLanguageResultExecution timeMemory
956634thinknoexitBoat (APIO16_boat)C++17
9 / 100
2 ms492 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 505; const ll MOD = 1e9 + 7; int a[N], b[N]; ll qs[2 * N], dp[2 * N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector<int> c; c.push_back(0); for (int i = 1;i <= n;i++) { cin >> a[i] >> b[i]; c.push_back(a[i] - 1); c.push_back(b[i]); } sort(c.begin(), c.end()); c.resize(unique(c.begin(), c.end()) - c.begin()); int m = c.size(); for (int i = 0;i < m;i++) { qs[i] = 1; } for (int i = 1;i <= n;i++) { memset(dp, 0, sizeof dp); int l = lower_bound(c.begin(), c.end(), a[i] - 1) - c.begin(); int r = lower_bound(c.begin(), c.end(), b[i]) - c.begin(); for (int j = l + 1;j < m;j++) { if (j <= r) dp[j] = (dp[j - 1] + (qs[j - 1]) * (c[j] - c[j - 1]) % MOD) % MOD; else dp[j] = dp[j - 1]; } for (int j = l + 1;j < m;j++) { qs[j] = (qs[j] + dp[j]) % MOD; } } cout << (qs[m - 1] - 1 + MOD) % MOD; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...