#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
const int MXN = 5005, INF = 3.9e18;
int m, n;
int ans = INF;
struct P {
int t, l, r, c;
int time, bound, pos, exp;
P() {}
P(int _t, int _l, int _r, int _c) : t(_t), l(_l), r(_r), c(_c) {
time = r + t;
bound = r - t;
pos = l - t;
exp = l + t;
}
} p[MXN];
ostream &operator<<(ostream &ss, P p) {
ss << '<' << p.t << ' ' << p.l << ' ' << p.r << ' ' << p.c << '>';
return ss;
}
vector<P> head, tail;
struct Q {
int t, b, c;
Q() {}
Q(int _t, int _b, int _c) : t(_t), b(_b), c(_c) {}
};
vector<Q> sen;
int CIN(int n) {
int t, l, r, c;
int C = 0;
FOR(i, 0, n) {
cin >> t >> l >> r >> c;
if (l == 1 && r == m) {
ans = min(ans, c);
continue;
}
if (l == 1) head.push_back(P(t, l - 1, r, c));
else if (r == m) tail.push_back(P(t, l - 1, r, c));
else {
p[C] = P(t, l - 1, r, c);
C++;
}
}
debug("HEAD");
for (auto &i : head) debug(i);
debug();
debug("TAIL");
for (auto &i : tail) debug(i);
return C;
}
void miku() {
cin >> m >> n;
n = CIN(n);
sort(p, p + n, [](P a, P b) -> bool {
return a.time < b.time;
});
for (auto &p : head) sen.push_back(Q(p.time, p.bound, p.c));
FOR(i, 0, n) {
int sml = INF;
for (auto &j : sen) {
if (j.t < p[i].exp) continue;
if (j.b < p[i].pos) continue;
sml = min(sml, j.c);
}
sen.push_back(Q(p[i].time, p[i].bound, sml + p[i].c));
}
// for (auto &i : sen) cout << i.t << ' ' << i.b << ' ' << i.c << '\n';
for (auto &p : tail) {
for (auto &j : sen) {
if (j.t < p.exp) continue;
if (j.b < p.pos) continue;
ans = min(ans, p.c + j.c);
}
}
cout << (ans == INF ? -1 : ans) << '\n';
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
Compilation message
treatment.cpp: In function 'long long int CIN(long long int)':
treatment.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
treatment.cpp:68:5: note: in expansion of macro 'debug'
68 | debug("HEAD");
| ^~~~~
treatment.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
treatment.cpp:69:26: note: in expansion of macro 'debug'
69 | for (auto &i : head) debug(i);
| ^~~~~
treatment.cpp:69:16: warning: unused variable 'i' [-Wunused-variable]
69 | for (auto &i : head) debug(i);
| ^
treatment.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
treatment.cpp:70:5: note: in expansion of macro 'debug'
70 | debug();
| ^~~~~
treatment.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
treatment.cpp:71:5: note: in expansion of macro 'debug'
71 | debug("TAIL");
| ^~~~~
treatment.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
treatment.cpp:72:26: note: in expansion of macro 'debug'
72 | for (auto &i : tail) debug(i);
| ^~~~~
treatment.cpp:72:16: warning: unused variable 'i' [-Wunused-variable]
72 | for (auto &i : tail) debug(i);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1568 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1568 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |