QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#520142 | #6455. Fancy Antiques | Andycipation | TL | 0ms | 3572kb | C++20 | 1.9kb | 2024-08-15 11:04:49 | 2024-08-15 11:04:49 |
Judging History
answer
/*
* author: ADMathNoob
* created: 08/14/24 22:28:48
* problem: https://qoj.ac/problem/6455
*/
/*
Comments about problem:
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...) 42
#endif
const int inf = 1e9 + 5;
const int N = 100;
const int M = 40;
int n, m, k;
int x[N], y[N], px[N], py[N];
vector<int> g[M];
int state[M];
int Solve(int v, int used) {
assert(used <= k);
if (v == m) {
int res = 0;
for (int i = 0; i < n; i++) {
int cost = inf;
if (state[x[i]] == 1) cost = min(cost, px[i]);
if (state[y[i]] == 1) cost = min(cost, py[i]);
if (cost == inf) return inf;
res += cost;
}
return res;
}
if (state[v] != -1) {
assert(state[v] == 1);
return Solve(v + 1, used);
}
bool has_self = false;
for (int id : g[v]) {
int u = x[id] ^ y[id] ^ v;
if (u == v) {
has_self = true;
}
}
int res = inf;
if (!has_self) {
state[v] = 0;
vector<int> changed;
for (int id : g[v]) {
int u = x[id] ^ y[id] ^ v;
assert(state[u] != 0);
if (state[u] == -1) {
state[u] = 1;
changed.push_back(u);
}
}
int new_used = used + changed.size();
if (new_used <= k) {
res = min(res, Solve(v + 1, new_used));
}
for (int u : changed) {
state[u] = -1;
}
}
if (used < k) {
state[v] = 1;
res = min(res, Solve(v + 1, used + 1));
}
state[v] = -1;
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
cin >> x[i] >> px[i] >> y[i] >> py[i];
--x[i]; --y[i];
g[x[i]].push_back(i);
g[y[i]].push_back(i);
}
fill(state, state + m, -1);
int ans = Solve(0, 0);
cout << (ans < inf ? ans : -1) << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
3 3 2 1 30 2 50 2 70 3 10 3 20 1 80
output:
60
result:
ok single line: '60'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
3 3 1 1 30 2 50 2 70 3 10 3 20 1 80
output:
-1
result:
ok single line: '-1'
Test #3:
score: -100
Time Limit Exceeded
input:
3 40 20 1 30 2 50 2 70 3 10 3 20 1 80