QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#337165 | #6372. Dance | nhuang685 | WA | 94ms | 9080kb | C++20 | 3.1kb | 2024-02-25 06:58:47 | 2024-02-25 06:58:47 |
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;
int sz = m * d;
int64_t ans = (int64_t)4e18;
for (int i = 0; i < (1 << m); ++i) {
bool g = true;
for (int j = 0; j < m - 1; ++j) {
if (p[d * j] && !(i & (1 << (m - 2 - i)) && !(i & (1 << (m - 1 - i))))) {
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 (k > 0 && p[loc - d] && !(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 & (2 << k)) {
if (i & (1 << 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();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
3 1 2 1 4 1 7
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 1ms
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: 3784kb
input:
1 1 441060 865580 6
output:
441060
result:
ok 1 number(s): "441060"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
1 2 524484 157528 88
output:
524484
result:
ok 1 number(s): "524484"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
1 3 607908 706373 65
output:
607908
result:
ok 1 number(s): "607908"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
1 1 724036 287921 39
output:
724036
result:
ok 1 number(s): "724036"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
1 4 807460 804061 17
output:
807460
result:
ok 1 number(s): "807460"
Test #8:
score: 0
Accepted
time: 7ms
memory: 3828kb
input:
1 7 974308 869046 72
output:
974308
result:
ok 1 number(s): "974308"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
1 4 221588 389967 17
output:
221588
result:
ok 1 number(s): "221588"
Test #10:
score: 0
Accepted
time: 94ms
memory: 9080kb
input:
1 9 704116 877292 5
output:
704116
result:
ok 1 number(s): "704116"
Test #11:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
1 3 820703 814856 86
output:
820703
result:
ok 1 number(s): "820703"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3544kb
input:
1 29 195626 207042 54
output:
195626
result:
ok 1 number(s): "195626"
Test #13:
score: 0
Accepted
time: 2ms
memory: 3608kb
input:
1 19 794740 856124 14
output:
794740
result:
ok 1 number(s): "794740"
Test #14:
score: -100
Wrong Answer
time: 1ms
memory: 3588kb
input:
1 28 444117 184242 58
output:
184242
result:
wrong answer 1st numbers differ - expected: '444117', found: '184242'