# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
249201 |
2020-07-14T13:26:10 Z |
sahil_k |
Boat (APIO16_boat) |
C++14 |
|
10 ms |
8320 KB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MOD 1000000007
int n;
int s_val[510], e_val[510];
vector<int> pts;
int s_id[510], e_id[510];
long long dp1[510][1010];
long long dp2[510][1010];
long long calc (long long a) {
return (a*(a-1)/2)%MOD;
}
int main () {
cin >> n;
for (int i=0; i<n; i++) {
cin >> s_val[i] >> e_val[i];
pts.push_back(s_val[i]);
pts.push_back(e_val[i]);
}
pts.push_back(0);
sort(pts.begin(), pts.end());
pts.resize(unique(pts.begin(), pts.end())-pts.begin());
for (int i=0; i<n; i++) {
s_id[i+1] = lower_bound(pts.begin(), pts.end(), s_val[i])-pts.begin();
e_id[i+1] = lower_bound(pts.begin(), pts.end(), e_val[i])-pts.begin();
}
int m = pts.size();
dp1[0][0] = 1;
for (int j=1; j<m; j++) {
dp2[0][j] = 1;
}
for (int i=1; i<=n; i++) {
dp1[i][0] = 1;
for (int j=1; j<m; j++) {
dp1[i][j] = dp1[i-1][j];
if (s_id[i] <= j && j <= e_id[i]) dp1[i][j] = (dp1[i][j]+dp2[i-1][j])%MOD;
dp2[i][j] = (MOD+dp2[i-1][j]-dp2[i-1][j-1])%MOD;
dp2[i][j] = (dp2[i][j]+dp2[i][j-1])%MOD;
if (s_id[i] < j && j <= e_id[i]) {
dp2[i][j] = (dp2[i][j]+(dp2[i-1][j-1]*(pts[j]-pts[j-1]))%MOD)%MOD;
dp2[i][j] = (dp2[i][j]+(dp1[i-1][j-1]*calc(pts[j]-pts[j-1]))%MOD)%MOD;
}
if (j == e_id[i]+1) dp2[i][j] = (MOD+dp2[i][j]+dp1[i][j-1]-dp1[i-1][j-1])%MOD;
}
}
cout << (MOD+dp2[n][m-1]+dp1[n][m-1]-1)%MOD << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8320 KB |
Output is correct |
2 |
Correct |
10 ms |
8320 KB |
Output is correct |
3 |
Correct |
7 ms |
8320 KB |
Output is correct |
4 |
Correct |
10 ms |
8320 KB |
Output is correct |
5 |
Correct |
7 ms |
8192 KB |
Output is correct |
6 |
Correct |
7 ms |
8320 KB |
Output is correct |
7 |
Correct |
7 ms |
8320 KB |
Output is correct |
8 |
Correct |
7 ms |
8320 KB |
Output is correct |
9 |
Correct |
7 ms |
8320 KB |
Output is correct |
10 |
Correct |
7 ms |
8320 KB |
Output is correct |
11 |
Correct |
8 ms |
8192 KB |
Output is correct |
12 |
Correct |
7 ms |
8320 KB |
Output is correct |
13 |
Correct |
7 ms |
8320 KB |
Output is correct |
14 |
Correct |
7 ms |
8320 KB |
Output is correct |
15 |
Correct |
8 ms |
8192 KB |
Output is correct |
16 |
Correct |
4 ms |
4992 KB |
Output is correct |
17 |
Correct |
6 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
5120 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8320 KB |
Output is correct |
2 |
Correct |
10 ms |
8320 KB |
Output is correct |
3 |
Correct |
7 ms |
8320 KB |
Output is correct |
4 |
Correct |
10 ms |
8320 KB |
Output is correct |
5 |
Correct |
7 ms |
8192 KB |
Output is correct |
6 |
Correct |
7 ms |
8320 KB |
Output is correct |
7 |
Correct |
7 ms |
8320 KB |
Output is correct |
8 |
Correct |
7 ms |
8320 KB |
Output is correct |
9 |
Correct |
7 ms |
8320 KB |
Output is correct |
10 |
Correct |
7 ms |
8320 KB |
Output is correct |
11 |
Correct |
8 ms |
8192 KB |
Output is correct |
12 |
Correct |
7 ms |
8320 KB |
Output is correct |
13 |
Correct |
7 ms |
8320 KB |
Output is correct |
14 |
Correct |
7 ms |
8320 KB |
Output is correct |
15 |
Correct |
8 ms |
8192 KB |
Output is correct |
16 |
Correct |
4 ms |
4992 KB |
Output is correct |
17 |
Correct |
6 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
5120 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Incorrect |
9 ms |
8192 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8320 KB |
Output is correct |
2 |
Correct |
10 ms |
8320 KB |
Output is correct |
3 |
Correct |
7 ms |
8320 KB |
Output is correct |
4 |
Correct |
10 ms |
8320 KB |
Output is correct |
5 |
Correct |
7 ms |
8192 KB |
Output is correct |
6 |
Correct |
7 ms |
8320 KB |
Output is correct |
7 |
Correct |
7 ms |
8320 KB |
Output is correct |
8 |
Correct |
7 ms |
8320 KB |
Output is correct |
9 |
Correct |
7 ms |
8320 KB |
Output is correct |
10 |
Correct |
7 ms |
8320 KB |
Output is correct |
11 |
Correct |
8 ms |
8192 KB |
Output is correct |
12 |
Correct |
7 ms |
8320 KB |
Output is correct |
13 |
Correct |
7 ms |
8320 KB |
Output is correct |
14 |
Correct |
7 ms |
8320 KB |
Output is correct |
15 |
Correct |
8 ms |
8192 KB |
Output is correct |
16 |
Correct |
4 ms |
4992 KB |
Output is correct |
17 |
Correct |
6 ms |
5120 KB |
Output is correct |
18 |
Correct |
4 ms |
4992 KB |
Output is correct |
19 |
Correct |
4 ms |
5120 KB |
Output is correct |
20 |
Correct |
4 ms |
4992 KB |
Output is correct |
21 |
Incorrect |
9 ms |
8192 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |