# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
551889 |
2022-04-21T20:21:46 Z |
nafis_shifat |
Boat (APIO16_boat) |
C++17 |
|
9 ms |
11224 KB |
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=1500+5;
const int inf=1e9;
const ll mod = 1e9 + 7;
ll bigmod(ll a, ll b) {
if(b == 0) return 1;
int mid = b / 2;
ll res = bigmod(a, mid);
res = res * res % mod;
if(b % 2 == 1) return a * res % mod;
return res;
}
ll last[mxn][mxn] = {};
ll dp[mxn][mxn] = {};
ll sum[mxn][mxn] = {};
ll fact[mxn], inv[mxn];
int main() {
fact[0] = 1;
inv[0] = 1;
for(int i = 1; i < mxn; i++) {
fact[i] = fact[i - 1] * i % mod;
inv[i] = bigmod(fact[i], mod - 2) % mod;
}
int n;
cin >> n;
int a[n + 1], b[n + 1];
int l[n + 1], r[n + 1];
vector<int> v;
v.push_back(0);
for(int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
v.push_back(a[i]);
v.push_back(a[i] - 1);
v.push_back(b[i]);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
int len[v.size() + 2];
for(int i = 1; i < v.size(); i++) len[i] = v[i] - v[i - 1];
for(int i = 1; i <= n; i++) {
l[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
r[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin();
}
dp[0][0] = 1;
for(int i = 0; i < v.size(); i++) sum[i][0] = 1;
ll ans = 0;
for(int p = 1; p <= n; p++) {
for(int i = l[p]; i <= r[p]; i++) {
ll tot = len[i];
ll found = 1;
for(int j = p - 1; j >= 0; j--) {
dp[i][j] = sum[i - 1][j] * tot % mod;
sum[i][p] = (sum[i][p] + dp[i][j]) % mod;
if(l[j] >= i && r[j] <= i) {
found++;
tot += (len[i] - found + 1) * inv[found] % mod;
}
}
}
for(int i = l[p]; i < v.size(); i++) sum[i][p] = (sum[i][p] + sum[i - 1][p]) % mod;
ans += sum[v.size() - 1][p];
}
cout<<ans % mod<<endl;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i = 1; i < v.size(); i++) len[i] = v[i] - v[i - 1];
| ~~^~~~~~~~~~
boat.cpp:57:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i = 0; i < v.size(); i++) sum[i][0] = 1;
| ~~^~~~~~~~~~
boat.cpp:77:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int i = l[p]; i < v.size(); i++) sum[i][p] = (sum[i][p] + sum[i - 1][p]) % mod;
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
11220 KB |
Output is correct |
2 |
Correct |
9 ms |
11220 KB |
Output is correct |
3 |
Correct |
8 ms |
11224 KB |
Output is correct |
4 |
Correct |
9 ms |
11220 KB |
Output is correct |
5 |
Correct |
9 ms |
11220 KB |
Output is correct |
6 |
Correct |
8 ms |
10096 KB |
Output is correct |
7 |
Correct |
7 ms |
9940 KB |
Output is correct |
8 |
Correct |
8 ms |
10580 KB |
Output is correct |
9 |
Correct |
9 ms |
10452 KB |
Output is correct |
10 |
Correct |
8 ms |
10576 KB |
Output is correct |
11 |
Correct |
8 ms |
10324 KB |
Output is correct |
12 |
Correct |
9 ms |
11092 KB |
Output is correct |
13 |
Correct |
8 ms |
10584 KB |
Output is correct |
14 |
Correct |
8 ms |
10072 KB |
Output is correct |
15 |
Correct |
8 ms |
10708 KB |
Output is correct |
16 |
Incorrect |
3 ms |
2260 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
11220 KB |
Output is correct |
2 |
Correct |
9 ms |
11220 KB |
Output is correct |
3 |
Correct |
8 ms |
11224 KB |
Output is correct |
4 |
Correct |
9 ms |
11220 KB |
Output is correct |
5 |
Correct |
9 ms |
11220 KB |
Output is correct |
6 |
Correct |
8 ms |
10096 KB |
Output is correct |
7 |
Correct |
7 ms |
9940 KB |
Output is correct |
8 |
Correct |
8 ms |
10580 KB |
Output is correct |
9 |
Correct |
9 ms |
10452 KB |
Output is correct |
10 |
Correct |
8 ms |
10576 KB |
Output is correct |
11 |
Correct |
8 ms |
10324 KB |
Output is correct |
12 |
Correct |
9 ms |
11092 KB |
Output is correct |
13 |
Correct |
8 ms |
10584 KB |
Output is correct |
14 |
Correct |
8 ms |
10072 KB |
Output is correct |
15 |
Correct |
8 ms |
10708 KB |
Output is correct |
16 |
Incorrect |
3 ms |
2260 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
3148 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
11220 KB |
Output is correct |
2 |
Correct |
9 ms |
11220 KB |
Output is correct |
3 |
Correct |
8 ms |
11224 KB |
Output is correct |
4 |
Correct |
9 ms |
11220 KB |
Output is correct |
5 |
Correct |
9 ms |
11220 KB |
Output is correct |
6 |
Correct |
8 ms |
10096 KB |
Output is correct |
7 |
Correct |
7 ms |
9940 KB |
Output is correct |
8 |
Correct |
8 ms |
10580 KB |
Output is correct |
9 |
Correct |
9 ms |
10452 KB |
Output is correct |
10 |
Correct |
8 ms |
10576 KB |
Output is correct |
11 |
Correct |
8 ms |
10324 KB |
Output is correct |
12 |
Correct |
9 ms |
11092 KB |
Output is correct |
13 |
Correct |
8 ms |
10584 KB |
Output is correct |
14 |
Correct |
8 ms |
10072 KB |
Output is correct |
15 |
Correct |
8 ms |
10708 KB |
Output is correct |
16 |
Incorrect |
3 ms |
2260 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |