QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#337153 | #6372. Dance | nhuang685 | WA | 93ms | 9116kb | C++20 | 3.0kb | 2024-02-25 06:46:22 | 2024-02-25 06:46:23 |
Judging History
answer
/**
* @file qoj6372-1.cpp
* @author n685
* @brief
* @date 2024-02-23
*
*
*/
#include <bits/stdc++.h>
#ifdef LOCAL
#include "dd/debug.h"
#else
#define dbg(...) 42
#define dbgR(...) 4242
#define dbgP(...) 420
#define dbgRP(...) 420420
void nline() {}
#endif
const int MX = 201;
int n, d;
int64_t a, b;
std::bitset<MX + 50> p;
void small() {
// std::array<std::vector<int64_t>, MX> dp;
std::array<std::vector<int64_t>, 2> dp;
dp.fill(std::vector<int64_t>(1 << d, (int64_t)4e18));
int par = 0;
for (int i = 0; i < (1 << d); ++i) {
int64_t val = 0;
for (int j = 0; j < d - 1; ++j) {
if ((i & (2 << j))) {
if (i & (1 << j)) {
val += b;
} else {
val += a;
}
}
}
dp[par][i] = val;
}
for (int i = d; i < MX; ++i) {
par = !par;
for (int j = 0; j < (1 << d); ++j) {
dp[par][j] = (int64_t)4e18;
auto apply = [&](int k) {
int64_t val = dp[!par][k];
if (k % 2) {
if (j % 2) {
val += b;
} else {
val += a;
}
}
dp[par][j] = std::min(dp[par][j], val);
};
int k = j / 2;
if ((j % 2) || !p[i - d]) {
apply(k);
}
k += (1 << (d - 1));
apply(k);
}
}
int64_t ans = (int64_t)4e18;
for (int i = 0; i < (1 << d); ++i) {
ans = std::min(ans, dp[par][i]);
}
std::cout << ans << '\n';
}
void big() {
int m = (MX + d - 1) / d;
int64_t ans = (int64_t)4e18;
for (int i = 0; i < (1 << m); ++i) {
bool g = true;
for (int j = 0; j < m; ++j) {
if (p[d * j] && !(i & (1 << j)) && !(i & (2 << j))) {
g = false;
break;
}
}
if (!g) {
continue;
}
std::array<std::vector<int64_t>, 2> dp;
dp.fill(std::vector<int64_t>(1 << m, (int64_t)4e18));
dp[0][i] = 0;
int par = 1;
for (int j = 1; j < d; ++j) {
for (int k = 0; k < m; ++k) {
for (int l = 0; l < (1 << m); ++l) {
dp[par][l] = (int64_t)4e18;
int loc = k * d + j;
if (l > 0 && p[loc] && !(l & 1) && !(l & 2)) {
continue;
}
dp[par][l] =
std::min(dp[!par][l / 2],
dp[!par][l / 2 + (1 << (m - 1))] + (l % 2) ? b : a);
par = !par;
}
}
}
par = !par;
for (int j = 0; j < (1 << m); ++j) {
for (int k = 0; k < m - 1; ++k) {
if (j & (1 << k)) {
if (i & (2 << k)) {
dp[par][j] += b;
} else {
dp[par][j] += a;
}
}
}
ans = std::min(ans, dp[par][j]);
}
}
std::cout << ans << '\n';
}
int main() {
#ifndef LOCAL
std::cin.tie(nullptr)->sync_with_stdio(false);
#endif
std::cin >> n >> d >> a >> b;
for (int i = 0; i < n; ++i) {
int x;
std::cin >> x;
--x;
p[x] = 1;
}
d *= 2;
if (d <= 20) {
small();
} else {
big();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3752kb
input:
3 1 2 1 4 1 7
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
3 1 7 1 4 1 7
output:
11
result:
ok 1 number(s): "11"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
1 1 441060 865580 6
output:
441060
result:
ok 1 number(s): "441060"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
1 2 524484 157528 88
output:
524484
result:
ok 1 number(s): "524484"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
1 3 607908 706373 65
output:
607908
result:
ok 1 number(s): "607908"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
1 1 724036 287921 39
output:
724036
result:
ok 1 number(s): "724036"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
1 4 807460 804061 17
output:
807460
result:
ok 1 number(s): "807460"
Test #8:
score: 0
Accepted
time: 7ms
memory: 3544kb
input:
1 7 974308 869046 72
output:
974308
result:
ok 1 number(s): "974308"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3532kb
input:
1 4 221588 389967 17
output:
221588
result:
ok 1 number(s): "221588"
Test #10:
score: 0
Accepted
time: 93ms
memory: 9116kb
input:
1 9 704116 877292 5
output:
704116
result:
ok 1 number(s): "704116"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
1 3 820703 814856 86
output:
820703
result:
ok 1 number(s): "820703"
Test #12:
score: -100
Wrong Answer
time: 1ms
memory: 3816kb
input:
1 29 195626 207042 54
output:
0
result:
wrong answer 1st numbers differ - expected: '195626', found: '0'