// And you curse yourself for things you never done
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 5010;
const ll inf = 1e18 + 10;
int L[maxn], R[maxn], T[maxn], C[maxn];
ll dp[maxn];
bool mark[maxn];
bool ok(int l1, int r1, int t1, int l2, int r2, int t2){
if(t1 > t2)
swap(l1, l2), swap(r1, r2), swap(t1, t2);
int t = abs(t1-t2);
l1+= t, r1-= t;
if(l1 > r1)
return 0;
return min(r1, r2) + 1 >= max(l1, l2);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
int n, m;
cin >> n >> m;
fill(dp, dp + m, inf);
for(int i = 0; i < m; i++){
cin >> T[i] >> L[i] >> R[i] >> C[i];
if(L[i] == 1)
dp[i] = C[i];
}
for(int i = 0; i < m; i++){
int id = -1;
for(int j = 0; j < m; j++){
if(mark[j] == 0 && (id == -1 || dp[id] > dp[j]))
id = j;
}
assert(id != -1);
mark[id] = 1;
for(int j = 0; j < m; j++){
if(ok(L[id], R[id], T[id], L[j], R[j], T[j]))
dp[j] = min(dp[j], dp[id] + C[j]);
}
}
ll ans = inf;
for(int i = 0; i < m; i++){
if(R[i] == n)
ans = min(ans, dp[i]);
}
if(ans == inf)
ans = -1;
return cout << ans << endl, 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
768 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
768 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |