#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 3e5 + 10;
const int lim = 1e7 + 10;
int t[N], l[N], r[N];
int n, m;
ll dp[N], c[N];
vector <int> ed[N];
ll run() {
set <pair <ll, ll>> save;
for (int i = 1; i <= m; i++) {
if (l[i] == 1) {
save.insert({c[i], i});
dp[i] = min(dp[i], c[i]);
}
}
while (sz(save)) {
auto t = *(save.begin());
save.erase(t);
if (dp[t.s] < t.f)
continue;
for (auto x : ed[t.s]) {
if (dp[x] > t.f + c[x]) {
dp[x] = t.f + c[x];
save.insert({dp[x], x});
}
}
}
ll ans = 1e16;
for (int i = 1; i <= m; i++) {
if (r[i] == n)
ans = min(ans, dp[i]);
}
if (ans > 1e14)
return -1;
return ans;
}
ll solve() {
mem(dp, 0x3f);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> t[i] >> l[i] >> r[i] >> c[i];
}
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= m; j++) {
if (i == j)
continue;
if (abs(t[i] - t[j]) <= r[i] - l[j] + 1) {
ed[i].pb(j);
//ed[j].pb(i);
}
}
}
return run();
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
//solve();
cout << solve() << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1519 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
4 ms |
14940 KB |
Output is correct |
3 |
Correct |
4 ms |
14936 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Correct |
4 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14940 KB |
Output is correct |
7 |
Correct |
3 ms |
14936 KB |
Output is correct |
8 |
Correct |
4 ms |
14940 KB |
Output is correct |
9 |
Correct |
4 ms |
14940 KB |
Output is correct |
10 |
Correct |
4 ms |
14940 KB |
Output is correct |
11 |
Correct |
3 ms |
15140 KB |
Output is correct |
12 |
Correct |
4 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14940 KB |
Output is correct |
14 |
Correct |
4 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14940 KB |
Output is correct |
16 |
Correct |
3 ms |
14940 KB |
Output is correct |
17 |
Correct |
3 ms |
14940 KB |
Output is correct |
18 |
Correct |
4 ms |
14940 KB |
Output is correct |
19 |
Correct |
3 ms |
14940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
4 ms |
14940 KB |
Output is correct |
3 |
Correct |
4 ms |
14936 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Correct |
4 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14940 KB |
Output is correct |
7 |
Correct |
3 ms |
14936 KB |
Output is correct |
8 |
Correct |
4 ms |
14940 KB |
Output is correct |
9 |
Correct |
4 ms |
14940 KB |
Output is correct |
10 |
Correct |
4 ms |
14940 KB |
Output is correct |
11 |
Correct |
3 ms |
15140 KB |
Output is correct |
12 |
Correct |
4 ms |
14940 KB |
Output is correct |
13 |
Correct |
3 ms |
14940 KB |
Output is correct |
14 |
Correct |
4 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14940 KB |
Output is correct |
16 |
Correct |
3 ms |
14940 KB |
Output is correct |
17 |
Correct |
3 ms |
14940 KB |
Output is correct |
18 |
Correct |
4 ms |
14940 KB |
Output is correct |
19 |
Correct |
3 ms |
14940 KB |
Output is correct |
20 |
Correct |
184 ms |
82772 KB |
Output is correct |
21 |
Correct |
186 ms |
82852 KB |
Output is correct |
22 |
Correct |
80 ms |
16316 KB |
Output is correct |
23 |
Correct |
78 ms |
16272 KB |
Output is correct |
24 |
Correct |
142 ms |
64876 KB |
Output is correct |
25 |
Correct |
110 ms |
50256 KB |
Output is correct |
26 |
Correct |
109 ms |
48496 KB |
Output is correct |
27 |
Correct |
106 ms |
54868 KB |
Output is correct |
28 |
Correct |
139 ms |
64596 KB |
Output is correct |
29 |
Correct |
106 ms |
49292 KB |
Output is correct |
30 |
Correct |
96 ms |
53332 KB |
Output is correct |
31 |
Correct |
98 ms |
55888 KB |
Output is correct |
32 |
Correct |
191 ms |
79188 KB |
Output is correct |
33 |
Correct |
170 ms |
116308 KB |
Output is correct |
34 |
Correct |
177 ms |
78660 KB |
Output is correct |
35 |
Correct |
192 ms |
79444 KB |
Output is correct |
36 |
Correct |
180 ms |
116440 KB |
Output is correct |
37 |
Correct |
177 ms |
78520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1519 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |