Submission #1046521

#TimeUsernameProblemLanguageResultExecution timeMemory
1046521Halym2007Boat (APIO16_boat)C++17
31 / 100
1394 ms524288 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e2 + 5; const int NN = 1e6 + 5; #define ll long long ll a[N], b[N]; int dp[NN], mod = 1e9 + 7, n, p[NN]; map <ll, int> m; int main () { // freopen ("input.txt", "r", stdin); ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i] >> b[i]; } for (int i = 1; i <= n; ++i) { for (int j = a[i]; j <= b[i]; ++j) { m[j] = 1; } } int san = 0; for (auto i : m) { m[i.first] = ++san; } for (int i = 1; i <= n; ++i) { a[i] = m[a[i]]; b[i] = m[b[i]]; } dp[0] = 1; for (int i = 1; i <= n; ++i) { assert (b[i] <= NN); for (int j = 0; j < b[i]; ++j) { p[j] = dp[j]; if (j != 0) { p[j] += p[j - 1]; p[j] %= mod; } } for (int j = b[i]; j >= a[i]; j--) { int sum = 0; if (j) sum = p[j - 1]; dp[j] += sum; dp[j] %= mod; } } int jog = 0; for (int i = 1; i <= san; ++i) { jog += dp[i]; jog %= mod; } cout << jog; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...