//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 5005
#define pii pair<ll, ll>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1LL<<60;
bool adj[maxn][maxn], mark[maxn];
bool vis[maxn];
void dfs(int n, int tot) {
vis[n] = 1;
for (int v = 1;v <= tot;v++) {
if (adj[n][v] && mark[v] && !vis[v]) {
dfs(v, tot);
}
}
}
struct rect{
int x1, y1, x2, y2;
int cost;
rect(){x1 = y1 = x2 = y2 = cost = 0;}
bool ins(int x, int y){
return x >= x1 && x <= x2 && y >= y1 && y <= y2;
}
bool inter(rect r) {
return ins(r.x1, r.y1) || ins(r.x1, r.y2) || ins(r.x2, r.y1) || ins(r.x2, r.y2)
|| r.ins(x1, y1) || r.ins(x1, y2) || r.ins(x2, y1) || r.ins(x2, y2);
}
} a[maxn];
ll dis[maxn];
int main() {
io
int L, n;
cin >> L >> n;
for (int i = 1;i <= n;i++) {
int t, l, r, c;
cin >> t >> l >> r >> c;
a[i].x1 = t - r, a[i].x2 = t - l, a[i].y1 = t + l, a[i].y2 = t + r;
a[i].cost = c;
if (r == L) {
adj[0][i] = 1;
}
if (l == 1) {
adj[i][n+1] = 1;
}
}
for (int i = 1;i <= n;i++) {
dis[i] = inf;
for (int j = i + 1;j <= n;j++) {
adj[i][j] = adj[j][i] = a[i].inter(a[j]);
}
}
for (int i = 0;i <= n + 1;i++) {
pary(adj[i], adj[i] + n + 2);
}
ll ans = inf;
for (int i = 0;i < (1<<n);i++) {
for (int j = 0;j <= n;j++) mark[j] = 0, vis[j] = 0;
mark[n+1] = 1;
vis[n+1] = 0;
ll val = 0;
for (int j = 0;j < n;j++) {
if (i & (1<<j)) mark[j+1] = 1, val += a[j+1].cost;
}
dfs(0, n+1);
if (vis[n+1]) {
ans = min(ans, val);
}
}
if (ans == inf) cout << -1 << endl;
else cout << ans << endl;
/*
dis[n+1] = inf;
priority_queue<pii, vector<pii>, greater<pii> > pq;
pq.push({0, 0});
while (pq.size()) {
auto [d, cur] = pq.top();
pq.pop();
if (d != dis[cur]) continue;
debug(cur, d);
for (int i = 1;i <= n + 1;i++) {
if (adj[cur][i] && d + a[i].cost < dis[i]) {
dis[i] = d + a[i].cost;
pq.push({dis[i], i});
}
}
}
cout << (dis[n+1] == inf ? -1 : dis[n+1]) << "\n";
*/
}
Compilation message
treatment.cpp: In function 'int main()':
treatment.cpp:13:19: warning: statement has no effect [-Wunused-value]
13 | #define pary(...) 0
| ^
treatment.cpp:68:3: note: in expansion of macro 'pary'
68 | pary(adj[i], adj[i] + n + 2);
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
33 ms |
2728 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
18 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
18 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
33 ms |
2728 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |