# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
946739 |
2024-03-15T01:25:20 Z |
Ice_man |
Boat (APIO16_boat) |
C++14 |
|
1 ms |
600 KB |
#include <iostream>
#include <chrono>
#include <set>
#include <vector>
#include <map>
#include <cstring>
#include <algorithm>
#define maxn 1005
#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;
}
long long m[maxn * 2];
long long inv_mod()
{
m[1] = 1;
for(long long i = 2; i < maxn * 2; i++)
m[i] = (mod / i) * (mod - m[mod % i]) % mod;
}
long long l[maxn], r[maxn];
long long n;
long long dp[maxn][maxn];
void read()
{
cin >> n;
for(long long i = 1; i <= n; i++)
cin >> l[i] >> r[i];
}
long long ans = 0;
vector <long long> v;
void pre()
{
for(long long i = 1; i <= n; i++)
{
v.pb(l[i]);
v.pb(r[i] + 1);
}
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
for(long long i = 1; i <= n; i++)
{
l[i] = lower_bound(v.begin(), v.end(), l[i]) - v.begin() + 1;
r[i] = lower_bound(v.begin(), v.end(), r[i] + 1) - v.begin() + 1;
}
}
void calc_dp()
{
dp[0][0] = 1;
long long a , br , c;
for(long long i = 1; i < v.size(); i++)
{
dp[i][0] = 1;
for(long long j = 1; j <= n; j++)
{
dp[i][j] = dp[i - 1][j];
if(l[j] > i)
continue;
if(i >= r[j])
continue;
a = v[i] - v[i - 1];
br = 1;
c = v[i] - v[i - 1];
for(long long k = j - 1; k > -1; k--)
{
dp[i][j] += dp[i - 1][k] * c;
dp[i][j] %= mod;
if(i >= l[k] && i < r[k])
{
c *= (a + br);
c %= mod;
c *= m[br + 1];
c %= mod;
br++;
}
}
}
}
long long ans = 0;
for(long long i = 1; i <= n; i++)
{
ans += dp[v.size() - 1][i];
ans %= mod;
}
cout << ans << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//startT = std::chrono::high_resolution_clock::now();
inv_mod();
/**for(long long i = 1; i <= 10; i++)
cout << m[i] << " ";
cout << endl;*/
read();
pre();
calc_dp();
return 0;
}
Compilation message
boat.cpp: In function 'long long int inv_mod()':
boat.cpp:43:1: warning: no return statement in function returning non-void [-Wreturn-type]
43 | }
| ^
boat.cpp: In function 'void calc_dp()':
boat.cpp:91:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for(long long i = 1; i < v.size(); i++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |