#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int, int > PII;
#define F first
#define S second
#define mkp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
const ll ool = 1e18 + 9;
const int N = 3e5 + 3, oo = 1e9 + 9;
int n, m, a[N], b[N], c[N], cost[N];
ll d[N], ans = ool;
int main() {
#ifdef krauch
freopen("input.txt", "r", stdin);
#endif
scanf("%d%d", &m, &n);
forn(i, 1, m) {
scanf("%d%d%d%d", a + i, b + i, c + i, cost + i);
cost[2 * m - i + 1] = cost[i];
a[2 * m - i + 1] = a[i];
b[2 * m - i + 1] = b[i];
c[2 * m - i + 1] = c[i];
}
forn(i, 1, m) {
d[i] = ool;
if (a[i] == 1) d[i] = cost[i];
forn(j, 1, i - 1) {
if (a[i] <= c[j] && c[j] <= b[i]) d[i] = min(d[i], d[j] + cost[i]);
}
d[2 * m - i + 1] = d[i];
}
forn(i, m + 1, 2 * m) {
forn(j, m + 1, i - 1) {
if (a[j] <= c[i] && c[i] <= b[j]) d[i] = min(d[i], d[j] + cost[i]);
}
if (b[i] == n) ans = min(ans, d[i]);
}
cout << (ans == ool ? -1 : ans) << "\n";
return 0;
}
Compilation message
pinball.cpp: In function 'int main()':
pinball.cpp:28:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &m, &n);
^
pinball.cpp:30:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", a + i, b + i, c + i, cost + i);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
1 ms |
352 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
1 ms |
532 KB |
Output is correct |
5 |
Correct |
1 ms |
532 KB |
Output is correct |
6 |
Correct |
2 ms |
532 KB |
Output is correct |
7 |
Correct |
2 ms |
532 KB |
Output is correct |
8 |
Correct |
1 ms |
532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
568 KB |
Output is correct |
2 |
Correct |
2 ms |
696 KB |
Output is correct |
3 |
Correct |
2 ms |
696 KB |
Output is correct |
4 |
Correct |
2 ms |
696 KB |
Output is correct |
5 |
Correct |
2 ms |
696 KB |
Output is correct |
6 |
Correct |
2 ms |
696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
696 KB |
Output is correct |
2 |
Correct |
2 ms |
696 KB |
Output is correct |
3 |
Correct |
7 ms |
696 KB |
Output is correct |
4 |
Correct |
8 ms |
808 KB |
Output is correct |
5 |
Correct |
7 ms |
808 KB |
Output is correct |
6 |
Correct |
8 ms |
824 KB |
Output is correct |
7 |
Correct |
3 ms |
864 KB |
Output is correct |
8 |
Correct |
7 ms |
1008 KB |
Output is correct |
9 |
Correct |
4 ms |
1008 KB |
Output is correct |
10 |
Correct |
6 ms |
1008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
582 ms |
1668 KB |
Output is correct |
2 |
Execution timed out |
1057 ms |
2284 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |