QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#297081 | #7988. 史莱姆工厂 | Heltion# | WA | 6ms | 3744kb | C++20 | 2.3kb | 2024-01-03 22:27:47 | 2024-01-03 22:27:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(...) 417
#endif
using i64 = int64_t;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cout << fixed << setprecision(20);
int n, k, w;
cin >> n >> k >> w;
vector<int> m(n), c(n);
for (int& ci : c) { cin >> ci; }
for (int& mi : m) { cin >> mi; }
vector<int> p(2 * k - 1);
for (int i = k; i <= 2 * k - 2; i += 1) { cin >> p[i]; }
vector f(n, vector<i64>(n, -1e18));
vector g(n, vector<i64>(n, -1e18));
vector h(n, vector<i64>(2 * k - 1));
for (int j = 0; j < n; j += 1) {
for (int i = j; i >= 0; i -= 1) {
if (i == j) {
f[i][j] = g[i][j] = p[k] - (k - m[i]) * w;
continue;
}
for (int k = i; k < j; k += 1) {
f[i][j] = max(f[i][j],
max(f[i][k], g[i][k]) + max(f[k + 1][j], g[k + 1][j]));
}
if (c[i] == c[j]) {
ranges::fill(h[i], -(i64)1e18);
h[i][m[i]] = 0;
for (int x = i + 1; x <= j; x += 1) {
ranges::fill(h[x], -(i64)1e18);
if (c[x] == c[i]) {
for (int y = i; y < x; y += 1) {
if (c[y] == c[i]) {
i64 wt = 0;
if (y + 1 == x) {
wt = 0;
} else if (y + 2 == x) {
wt = p[k] - (k - m[y + 1]) * w;
} else {
wt = max(wt, g[y + 1][x - 1]);
for (int k = y + 1; k < x - 1; k += 1) {
if (c[k] != c[i] and c[k + 1] != c[j]) {
wt =
max(wt, max(f[y + 1][k], g[y + 1][k]) +
max(f[k + 1][x - 1], g[k + 1][x - 1]));
}
}
}
for (int z = 1; z < k; z += 1) {
h[x][z + m[x]] = max(h[x][z + m[x]], wt + h[y][z]);
}
}
}
}
}
for (int z = 1; z <= 2 * k - 2; z += 1) {
if (z < k) {
g[i][j] = max(g[i][j], h[j][z] + p[k] - (k - z) * w);
} else {
g[i][j] = max(g[i][j], h[j][z] + p[z]);
}
}
}
debug(i, j, f[i][j], g[i][j]);
}
}
cout << max(f[0][n - 1], g[0][n - 1]);
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3552kb
input:
4 5 6 2 1 2 3 3 3 3 4 5 7 9 11
output:
-1
result:
ok single line: '-1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
5 7 500 2 3 2 3 2 5 6 6 6 4 1000 900 800 400 200 50
output:
1400
result:
ok single line: '1400'
Test #3:
score: 0
Accepted
time: 6ms
memory: 3744kb
input:
150 10 465782 6 1 4 3 2 6 1 3 5 3 4 6 1 2 1 5 1 6 2 1 5 4 6 1 3 2 6 5 4 3 1 6 3 4 1 4 1 6 3 6 1 4 2 4 6 4 3 1 5 6 4 2 1 4 6 2 5 1 3 1 4 6 5 6 3 2 3 4 2 3 6 3 5 2 6 1 5 4 5 2 4 1 4 3 4 1 3 2 6 1 4 5 4 6 2 1 3 1 2 1 3 5 2 3 2 6 5 3 1 4 1 5 1 6 2 5 4 2 4 1 4 2 5 6 4 3 5 1 3 2 5 4 6 4 3 5 3 4 5 3 2 1 4 ...
output:
392867316
result:
ok single line: '392867316'
Test #4:
score: -100
Wrong Answer
time: 4ms
memory: 3676kb
input:
150 10 10105 8 6 8 6 8 3 8 5 8 5 1 5 1 5 6 5 6 5 6 7 6 5 6 1 6 4 6 4 3 4 9 4 1 4 1 4 1 5 1 9 1 4 1 9 1 9 3 9 1 9 5 9 8 9 8 5 8 7 8 4 8 6 8 6 2 6 9 6 4 6 5 6 5 3 5 1 5 4 5 8 5 8 9 8 7 8 6 8 1 8 1 8 1 8 1 6 1 7 1 7 2 7 4 7 6 7 4 7 4 5 4 7 4 7 4 3 4 3 7 3 2 3 8 3 4 3 4 8 4 7 4 9 4 2 4 2 7 2 8 2 7 2 9 2...
output:
9260890
result:
wrong answer 1st lines differ - expected: '9262990', found: '9260890'