#include <bits/stdc++.h>
using namespace std;
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
template <class A, class B> bool minimize(A &a, B b) { if (a > b) { a = b; return true; } return false; }
template <class A, class B> bool maximize(A &a, B b) { if (a < b) { a = b; return true; } return false; }
const int MAXN = 1e5 + 5;
int N, M;
long long dp[MAXN];
void you_make_it(void) {
cin >> N >> M;
vector <array <int, 4>> a(M);
for (auto &[t, l, r, c] : a) {
cin >> t >> l >> r >> c;
}
sort(ALL(a), [&] (const array <int, 4> &A, const array <int, 4> &B){
return (A[1] < B[1] || (A[1] == B[1] && A[2] < B[2]));
});
memset(dp, 0x3f, sizeof dp);
REP(i, M) if(a[i][1] == 1) dp[i] = a[i][3];
REP(i, M) FORE(j, i + 1, M) {
if(abs(a[i][0] - a[j][0]) <= abs(a[i][2] - a[j][1]) && a[i][2] >= a[j][1] - 1) {
minimize(dp[j], dp[i] + a[j][3]);
}
}
long long ans = 1E18;
REP(i, M) if(a[i][2] == N) minimize(ans, dp[i]);
// REP(i, M) cout << dp[i] << " \n"[i + 1 == M];
cout << (ans >= 1E18 ? -1 : ans);
}
signed main() {
#ifdef LOCAL
freopen("TASK.inp", "r", stdin);
freopen("TASK.out", "w", stdout);
#endif
auto start_time = chrono::steady_clock::now();
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
you_make_it();
auto end_time = chrono::steady_clock::now();
cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;
return (0 ^ 0);
}
// Dream it. Wish it. Do it.
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3037 ms |
5972 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3037 ms |
5972 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |