# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
249121 |
2020-07-14T11:38:25 Z |
sahil_k |
Boat (APIO16_boat) |
C++14 |
|
4 ms |
4352 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 dp[510][1010]; // No. of ways to send exactly j boats from i.
long long ttl;
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();
dp[0][0] = 1;
for (int i=1; i<=n; i++) {
ttl = 0;
dp[i][0] = 1;
for (int j=1; j<m; j++) {
dp[i][j] = dp[i-1][j];
ttl = (ttl+dp[i-1][j-1]*(pts[j]-pts[j-1]))%MOD;
if (s_id[i] <= j && j <= e_id[i]) dp[i][j] = (dp[i][j]+ttl)%MOD;
}
}
long long o = 0;
for (int j=1; j<m; j++) {
o = (o+dp[n][j]*(pts[j]-pts[j-1]))%MOD;
}
cout << o << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
4352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |