QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#297089 | #7988. 史莱姆工厂 | Heltion# | WA | 84ms | 3932kb | C++20 | 2.4kb | 2024-01-03 22:38:19 | 2024-01-03 22:38:19 |
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 = -1e18;
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]) or
c[y + 1] != c[x - 1]) {
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: 0ms
memory: 3488kb
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: 0ms
memory: 3572kb
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: 7ms
memory: 3884kb
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: 0
Accepted
time: 4ms
memory: 3656kb
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:
9262990
result:
ok single line: '9262990'
Test #5:
score: 0
Accepted
time: 7ms
memory: 3656kb
input:
150 10 491282 5 7 1 4 5 3 5 3 5 6 7 3 6 3 4 5 4 2 3 7 3 4 7 2 3 7 5 4 6 1 7 5 2 6 4 1 6 2 5 4 1 3 6 7 5 6 2 1 3 2 1 7 1 2 6 1 2 6 4 3 7 6 5 3 5 4 1 2 7 1 5 6 2 6 5 1 3 5 6 3 4 5 1 3 7 4 6 4 2 6 3 7 5 7 1 2 7 4 3 2 1 4 2 7 4 6 2 3 6 4 7 1 5 3 2 1 3 4 3 6 7 3 7 5 6 2 4 2 1 3 2 3 7 5 3 5 6 4 6 1 2 6 7 ...
output:
300542698
result:
ok single line: '300542698'
Test #6:
score: 0
Accepted
time: 5ms
memory: 3704kb
input:
150 10 999660 2 1 7 4 6 1 6 2 1 3 4 6 2 7 2 3 2 4 8 3 5 8 7 8 3 5 7 3 4 6 7 6 3 5 6 8 4 2 3 7 6 5 8 7 5 2 4 8 4 8 3 6 4 6 2 8 4 5 3 5 6 3 5 4 5 2 7 5 1 8 1 3 2 1 7 5 7 8 2 5 1 4 3 7 5 8 6 3 7 2 1 5 2 3 5 3 7 2 7 8 5 8 1 5 6 1 6 4 7 5 1 5 1 2 5 2 8 7 5 6 7 6 7 6 2 7 6 8 6 5 4 3 8 7 2 8 6 3 6 1 2 6 8 ...
output:
670043245
result:
ok single line: '670043245'
Test #7:
score: 0
Accepted
time: 5ms
memory: 3856kb
input:
150 10 657385 9 8 2 1 8 2 3 8 9 7 1 9 1 7 3 2 3 9 3 1 6 2 4 1 8 1 7 3 2 8 7 6 8 2 3 9 8 5 1 7 8 1 3 5 8 5 6 3 9 6 5 8 3 4 1 3 8 1 8 6 2 5 2 9 8 5 2 4 7 3 2 3 1 3 7 2 5 1 2 9 8 9 8 6 8 4 7 6 3 8 5 7 2 8 5 8 6 5 1 3 8 2 1 7 3 6 3 5 2 7 8 1 9 5 8 3 6 2 7 3 8 7 4 1 7 5 3 4 1 4 6 5 4 7 3 9 3 9 7 5 8 7 5 ...
output:
617669855
result:
ok single line: '617669855'
Test #8:
score: 0
Accepted
time: 4ms
memory: 3884kb
input:
150 10 610355 10 1 7 9 8 2 9 4 10 8 9 3 5 1 10 5 10 4 5 6 7 6 10 9 7 9 3 4 7 5 2 6 10 3 2 10 8 3 5 2 5 8 6 2 9 6 3 8 6 5 4 9 3 1 5 3 2 9 4 2 4 10 9 4 5 2 3 5 9 3 5 1 5 3 7 5 3 9 6 1 7 3 7 5 1 3 9 1 6 4 10 7 9 5 9 7 3 7 4 9 2 3 4 9 10 3 1 4 3 1 6 9 1 8 1 3 8 2 8 1 6 1 5 4 10 2 9 3 9 5 2 6 8 3 9 5 2 3...
output:
531487920
result:
ok single line: '531487920'
Test #9:
score: 0
Accepted
time: 3ms
memory: 3932kb
input:
150 10 213291 5 2 9 4 11 7 1 6 11 7 4 10 8 5 11 6 11 9 8 3 6 3 8 7 3 6 4 9 5 2 7 11 2 8 5 1 11 2 3 1 10 8 7 4 11 9 7 5 3 10 9 6 7 5 4 9 3 8 10 8 3 11 3 5 6 8 10 1 5 3 1 9 2 7 3 7 2 5 6 2 11 5 11 6 7 1 7 3 7 8 11 5 4 10 3 8 7 5 1 10 5 2 1 7 3 8 7 2 9 2 1 10 4 7 8 11 6 4 10 1 2 9 5 4 8 11 3 7 1 11 1 7...
output:
152312585
result:
ok single line: '152312585'
Test #10:
score: -100
Wrong Answer
time: 84ms
memory: 3628kb
input:
150 10 217802 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ...
output:
-11761308
result:
wrong answer 1st lines differ - expected: '-11543506', found: '-11761308'