# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
946526 | n3rm1n | Boat (APIO16_boat) | C++17 | 1932 ms | 524288 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// boat
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 505, MAXX = 1e6+10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, m;
int a[MAXN], b[MAXN];
unordered_map < int, int > id;
vector < int > g, u;
void read_hash()
{
cin >> n;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i] >> b[i];
for (int j = a[i]; j <= b[i]; ++ j)
g.push_back(j);
}
sort(g.begin(), g.end());
u.push_back(g[0]);
for (int i = 1; i < g.size(); ++ i)
{
if(u.back() != g[i])
u.push_back(g[i]);
}
for (int i = 0; i < u.size(); ++ i)
{
id[u[i]] = i+1;
}
}
int dp[MAXX];
const int mod = 1e9 + 7;
int pref[MAXX];
void solve()
{
int ans = 0;
int maxx = u.size();
for (int i = 1; i <= n; ++ i)
{
for (int j = id[b[i]]; j >= id[a[i]]; -- j)
{
dp[j] += pref[j-1] + 1;
dp[j] %= mod;
}
for (int j = id[a[i]]; j <= u.size(); ++ j)
pref[j] = (pref[j-1] + dp[j]) % mod;
}
ans = pref[maxx];
ans %= mod;
cout << ans << endl;
}
int main()
{
speed();
read_hash();
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |