QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#337147 | #6372. Dance | nhuang685 | WA | 0ms | 3592kb | C++20 | 2.9kb | 2024-02-25 06:38:07 | 2024-02-25 06:38:07 |
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;
dp.fill(std::vector<int64_t>(1 << d, (int64_t)4e18));
for (int i = 0; i < (1 << d); ++i) {
int64_t val = 0;
for (int j = 0; j < d - 1; ++j) {
if ((i & (1 << j))) {
if (i & (2 << j)) {
val += b;
} else {
val += a;
}
}
}
dp[d - 1][i] = val;
}
for (int i = d; i < MX; ++i) {
for (int j = 0; j < (1 << d); ++j) {
auto apply = [&](int k) {
int64_t val = dp[i - 1][k];
if (j % 2) {
if (k % 2) {
val += b;
} else {
val += a;
}
}
dp[i][j] = std::min(dp[i][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.back()[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();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3592kb
input:
3 1 2 1 4 1 7
output:
3
result:
wrong answer 1st numbers differ - expected: '5', found: '3'