#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;
ll dp[2][505][505];
int32_t main() {
int n, m;
cin >> n >> m;
vector<array<int, 4> > v(n+2);
set<int> s; s.insert(1); s.insert(m);
for(int i=1; i<=n; i++) {
cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
s.insert(v[i][0]);
s.insert(v[i][1]);
s.insert(v[i][2]);
}
vector<int> comp(all(s));
for(int i=1; i<=n; i++) {
v[i][0] = lower_bound(all(comp), v[i][0]) - comp.begin();
v[i][1] = lower_bound(all(comp), v[i][1]) - comp.begin();
v[i][2] = lower_bound(all(comp), v[i][2]) - comp.begin();
}
for(int i=0; i<comp.size(); i++)
for(int j=i; j<comp.size(); j++) dp[0][i][j] = dp[1][i][j] = 1e16;
for(int i=0; i<comp.size(); i++) dp[0][i][i] = 0;
for(int i=n+1; i>=2; i--) {
for(int j=0; j<comp.size(); j++) {
for(int k=j; k<comp.size(); k++) {
if(dp[0][j][k] >= 1e16) continue;
dp[1][j][k] = min(dp[1][j][k], dp[0][j][k]);
if(j <= v[i-1][2] && v[i-1][2] <= k) {
int l = min(j, v[i-1][0]);
int r = max(k, v[i-1][1]);
dp[1][l][r] = min(dp[1][l][r], dp[0][j][k] + v[i-1][3]);
}
}
}
swap(dp[0], dp[1]);
}
if(dp[0][0][comp.size()-1] >= 1e16) cout << -1 << '\n';
else cout << dp[0][0][comp.size()-1] << '\n';
return 0;
}
Compilation message
pinball.cpp: In function 'int32_t main()':
pinball.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i=0; i<comp.size(); i++)
| ~^~~~~~~~~~~~
pinball.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int j=i; j<comp.size(); j++) dp[0][i][j] = dp[1][i][j] = 1e16;
| ~^~~~~~~~~~~~
pinball.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i=0; i<comp.size(); i++) dp[0][i][i] = 0;
| ~^~~~~~~~~~~~
pinball.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int j=0; j<comp.size(); j++) {
| ~^~~~~~~~~~~~
pinball.cpp:51:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int k=j; k<comp.size(); k++) {
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
3 ms |
4440 KB |
Output is correct |
3 |
Correct |
3 ms |
4188 KB |
Output is correct |
4 |
Correct |
3 ms |
4188 KB |
Output is correct |
5 |
Correct |
3 ms |
4184 KB |
Output is correct |
6 |
Correct |
4 ms |
4188 KB |
Output is correct |
7 |
Correct |
3 ms |
4184 KB |
Output is correct |
8 |
Correct |
3 ms |
4188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
3 ms |
4440 KB |
Output is correct |
3 |
Correct |
3 ms |
4188 KB |
Output is correct |
4 |
Correct |
3 ms |
4188 KB |
Output is correct |
5 |
Correct |
3 ms |
4184 KB |
Output is correct |
6 |
Correct |
4 ms |
4188 KB |
Output is correct |
7 |
Correct |
3 ms |
4184 KB |
Output is correct |
8 |
Correct |
3 ms |
4188 KB |
Output is correct |
9 |
Correct |
38 ms |
4184 KB |
Output is correct |
10 |
Correct |
40 ms |
4188 KB |
Output is correct |
11 |
Correct |
42 ms |
4440 KB |
Output is correct |
12 |
Runtime error |
5 ms |
8536 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
3 ms |
4440 KB |
Output is correct |
3 |
Correct |
3 ms |
4188 KB |
Output is correct |
4 |
Correct |
3 ms |
4188 KB |
Output is correct |
5 |
Correct |
3 ms |
4184 KB |
Output is correct |
6 |
Correct |
4 ms |
4188 KB |
Output is correct |
7 |
Correct |
3 ms |
4184 KB |
Output is correct |
8 |
Correct |
3 ms |
4188 KB |
Output is correct |
9 |
Correct |
38 ms |
4184 KB |
Output is correct |
10 |
Correct |
40 ms |
4188 KB |
Output is correct |
11 |
Correct |
42 ms |
4440 KB |
Output is correct |
12 |
Runtime error |
5 ms |
8536 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4184 KB |
Output is correct |
2 |
Correct |
3 ms |
4440 KB |
Output is correct |
3 |
Correct |
3 ms |
4188 KB |
Output is correct |
4 |
Correct |
3 ms |
4188 KB |
Output is correct |
5 |
Correct |
3 ms |
4184 KB |
Output is correct |
6 |
Correct |
4 ms |
4188 KB |
Output is correct |
7 |
Correct |
3 ms |
4184 KB |
Output is correct |
8 |
Correct |
3 ms |
4188 KB |
Output is correct |
9 |
Correct |
38 ms |
4184 KB |
Output is correct |
10 |
Correct |
40 ms |
4188 KB |
Output is correct |
11 |
Correct |
42 ms |
4440 KB |
Output is correct |
12 |
Runtime error |
5 ms |
8536 KB |
Execution killed with signal 11 |
13 |
Halted |
0 ms |
0 KB |
- |