# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
946716 | Ice_man | Boat (APIO16_boat) | C++14 | 2079 ms | 435860 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.
#include <iostream>
#include <chrono>
#include <set>
#include <vector>
#include <map>
#include <cstring>
#define maxn 505
#define maxlog 20
#define mod 1000000007
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;
#pragma GCC optimize("O3" , "Ofast" , "unroll-loops" , "fast-math")
#pragma GCC target("avx2")
using namespace std;
std::chrono::high_resolution_clock::time_point startT, currT;
constexpr double TIME_MULT = 1;
double timePassed()
{
using namespace std::chrono;
currT = high_resolution_clock::now();
double time = duration_cast<duration<double>>(currT - startT).count();
return time * TIME_MULT;
}
int l[maxn], r[maxn];
int n;
int dp[maxn];
void read()
{
cin >> n;
for(int i = 0; i < n; i++)
cin >> l[i] >> r[i];
}
int ans = 0;
void calc_dp()
{
set <int> s;
for(int i = 0; i < n; i++)
for(int j = l[i]; j <= r[i]; j++)
s.insert(j);
vector <int> v;
for(int e : s)
v.pb(e);
/**for(int e : v)
cout << e << " ";
cout << endl;*/
map <int , int> mem;
for(int i = 0; i < v.size(); i++)
mem[v[i]] = i + 1;
for(int i = 0; i < n; i++)
{
l[i] = mem[l[i]];
r[i] = mem[r[i]];
}
/**for(int i = 0; i < n; i++)
cout << l[i] << " - " << r[i] << endl;*/
for(int i = 0; i <= v.size(); i++)
dp[i] = 0;
dp[0] = 1;
long long pom = 0 , prev;
for(int i = 0; i < n; i++)
{
pom = 0LL;
for(int j = 0; j <= r[i]; j++)
{
prev = dp[j];
if(j >= l[i])
{
dp[j] += pom;
dp[j] %= mod;
}
pom += prev;
pom %= mod;
}
}
long long ans = 0;
for(int i = 1; i <= v.size(); i++)
{
ans += dp[i];
ans %= mod;
}
cout << ans << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//startT = std::chrono::high_resolution_clock::now();
read();
calc_dp();
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... |