QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#319666 | #5441. Quartz Collection | duckindog | RE | 4ms | 20232kb | C++14 | 1.3kb | 2024-02-03 00:43:52 | 2024-02-03 00:43:52 |
Judging History
answer
//from duckindog wth depression
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m;
int a[N], b[N];
int f[1 << 10][1 << 10][2][2];
int dp(int mask1, int mask2, bool p, bool l) {
if (mask1 == (1 << n) - 1 && mask1 == mask2) return 0;
auto &ret = f[mask1][mask2][p][l];
if (ret > -1) return ret;
if (p) {
ret = 1e9;
for (int i = 1; i <= n; ++i) {
if (mask1 >> i - 1 & 1) continue;
int c = (mask2 >> i - 1 & 1) ? b[i] : a[i];
int nmask = (mask1 | (1 << i - 1));
ret = min(ret, dp(nmask, mask2, l == 1 ? 1 - p : p, (l + 1) % 2) + c);
}
} else {
ret = 0;
for (int i = 1; i <= n; ++i) {
if (mask2 >> i - 1 & 1) continue;
int nmask = (mask2 | (1 << i - 1));
ret = max(ret, dp(mask1, nmask, l == 1 ? 1 - p : p, (l + 1) % 2));
}
}
return ret;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("duck.inp", "r")) {
freopen("duck.inp", "r", stdin);
freopen("duck.out", "w", stdout);
}
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
memset(f, -1, sizeof f);
cout << dp(0, 0, 1, 1) << "\n";
for (int i = 1; i <= m; ++i) {
int t, x, y; cin >> t >> x >> y; a[t] = x; b[t] = y;
memset(f, -1, sizeof f);
cout << dp(0, 0, 1, 1) << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 20232kb
input:
4 5 2 4 5 7 1 7 2 1 4 5 2 1 6 2 4 4 3 2 1 3 3 6 6
output:
13 14 15 14 10 13
result:
ok 6 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 20132kb
input:
1 1 1 1 1 1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: -100
Runtime Error
input:
100 100 6 7 100 8 5 61 5 75 59 65 51 47 83 37 34 54 87 46 4 26 21 87 12 97 86 68 60 11 62 76 14 83 29 31 91 62 57 80 47 75 85 97 62 77 91 86 14 25 48 77 83 65 39 61 78 77 45 46 90 74 100 91 86 98 55 5 84 42 91 69 100 4 74 98 60 37 75 44 41 12 15 34 36 1 99 16 7 87 36 26 79 42 41 84 17 98 72 16 38 55...