QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#153183 | #6849. Mr. Liang play Card Game | jrjyy# | WA | 4ms | 3988kb | C++20 | 1.8kb | 2023-08-29 16:03:07 | 2023-08-29 16:03:07 |
Judging History
answer
/* c.cpp */
#include <bits/stdc++.h>
using i64 = long long;
constexpr i64 inf = 1e18;
void solve() {
int n, m, R, P;
std::cin >> n >> m >> R >> P;
std::vector<int> a(n);
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
--a[i];
}
std::vector<int> v(m);
for (int i = 0; i < m; ++i) {
std::cin >> v[i];
}
std::vector s(m, std::vector<i64>(n + 1));
for (int i = 0; i < m; ++i) {
s[i][1] = v[i];
for (int j = 2; j <= n; j *= 2) {
s[i][j] = s[i][j / 2];
if (j <= (1 << (R - 1))) {
s[i][j] *= std::max(P, 2);
} else {
s[i][j] *= 2;
}
}
for (int j = 2; j <= n; ++j) {
s[i][j] = s[i][j & -j] + s[i][j & (j - 1)];
}
}
std::vector f(n + 1, std::vector<i64>(n + 1));
for (int i = 0; i < n; ++i) {
f[i][i + 1] = v[a[i]];
}
for (int len = 2; len <= n; ++len) {
for (int l = 0; l + len <= n; ++l) {
int r = l + len;
for (int i = l + 1; i < r; ++i) {
f[l][r] = std::max(f[l][r], f[l][i] + f[i][r]);
}
int lst = l, cnt = 1;
i64 sum = 0;
for (int i = l + 1; i < r; ++i) {
if (a[i] == a[l]) {
sum += f[lst + 1][i];
lst = i;
cnt += 1;
}
}
sum += f[lst + 1][r];
f[l][r] = std::max(f[l][r], sum + s[a[l]][cnt]);
}
}
std::cout << f[0][n] << '\n';
}
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 3988kb
input:
50 55 2 3 8 2 1 2 1 2 2 2 1 1 1 2 2 1 1 2 1 1 2 2 1 1 1 1 1 2 2 1 1 2 2 2 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 2 1 2 2 2 1 1 1 42126 55001 55 3 1 8 2 3 1 1 3 3 3 2 1 2 1 2 1 2 1 3 1 3 3 2 3 2 2 3 1 1 2 2 2 2 2 3 3 2 2 2 3 1 3 2 1 2 2 1 1 2 2 3 3 3 1 1 3 3 2 39105 57552 26545 55 2 3 9 2 1 2 2 2 2 2 2 2 2 ...
output:
30933256 2330529 68098500 3661875 6700431 1021147 334792 859244 1057821 276184 1182470 1200828 1475228 3028111 796232 331782 440245 952455 977955 1210135 51990 1138694 311282 1044444 773077 1426404 4796750 1239955 1144503 120368 84132 2230930 1259948 680475 528194 599850 861273 1739942 1319720 11729...
result:
wrong answer 1st lines differ - expected: '38200162', found: '30933256'