QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#301499 | #6372. Dance | SolitaryDream | WA | 176ms | 10464kb | C++14 | 2.4kb | 2024-01-09 23:34:31 | 2024-01-09 23:34:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 500;
int n, d, a, b;
bool req[N];
inline int Calc(int x, int y) {
if (x == 0 && y == 1) return a;
else if (y == 1) return b;
else return 0;
}
void Solve1() {
static int f[2][1 << 21];
for (int i = 1; i < (1 << d + 1); ++i) f[0][i] = 1e9;
f[0][0] = 0;
for (int i = 0; i < 200; ++i) {
int ni = (i + 1) & 1;
for (int j = 0; j < (1 << d + 1); ++j) f[ni][j] = 1e9;
// put on i+1
for (int j = 0; j < (1 << d + 1); ++j) {
// put on i+1
int nf = f[i & 1][j] + Calc(j & 1, 1);
int nj = j >> 1 | 1;
f[ni][nj] = min(f[ni][nj], nf);
// not put on i + 1
if (~j >> 1 & 1) {
int nf = f[i & 1][j] + Calc(j & 1, 0);
int nj = j >> 1 | (req[i] << d);
f[ni][nj] = min(f[ni][nj], nf);
}
}
}
cout << f[200 & 1][0] << endl;
}
inline void Solve2() {
static int f[2][1 << 10];
int num = 200 / d;
int ans = 1e9;
for (int st = 0; st < (1 << num); ++st) {
f[0][st] = 0;
for (int i = 0; i < (1 << num); ++i) f[0][i] = 1e9;
for (int delta = 0; delta + 1 < d; ++delta) {
int ndelta = (delta + 1) & 1;
for (int i = 0; i < num; ++i) {
for (int j = 0; j < (1 << num); ++j) {
int pos = i * d + delta;
int nj = j | (1 << i);
f[ndelta][nj] = min(f[ndelta][nj], f[delta & 1][j] + Calc(j >> i, 1) + (delta + 1 == d - 1) * Calc(1, st >> i));
if (req[pos] || (pos - d >= 0 && req[pos - d] && (j >> (i - 1) & 1) == 0)) {
continue;
}
nj = j & ~(1 << i);
f[ndelta][nj] = min(f[ndelta][nj], f[delta & 1][j] + Calc(j >> i, 0) + (delta + 1 == d - 1) * Calc(0, st >> i));
}
}
}
for (int i = 0; i < (1 << num); ++i) ans = min(ans, f[(d - 1) & 1][i]);
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> d >> a >> b;
d *= 2;
for (int i = 1, x; i <= n; ++i) {
cin >> x;
req[x] = 1;
}
if (d <= 20) {
Solve1();
} else {
Solve2();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5604kb
input:
3 1 2 1 4 1 7
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5704kb
input:
3 1 7 1 4 1 7
output:
11
result:
ok 1 number(s): "11"
Test #3:
score: 0
Accepted
time: 0ms
memory: 5664kb
input:
1 1 441060 865580 6
output:
441060
result:
ok 1 number(s): "441060"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5696kb
input:
1 2 524484 157528 88
output:
524484
result:
ok 1 number(s): "524484"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5672kb
input:
1 3 607908 706373 65
output:
607908
result:
ok 1 number(s): "607908"
Test #6:
score: 0
Accepted
time: 0ms
memory: 5648kb
input:
1 1 724036 287921 39
output:
724036
result:
ok 1 number(s): "724036"
Test #7:
score: 0
Accepted
time: 0ms
memory: 5724kb
input:
1 4 807460 804061 17
output:
807460
result:
ok 1 number(s): "807460"
Test #8:
score: 0
Accepted
time: 11ms
memory: 5792kb
input:
1 7 974308 869046 72
output:
974308
result:
ok 1 number(s): "974308"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5608kb
input:
1 4 221588 389967 17
output:
221588
result:
ok 1 number(s): "221588"
Test #10:
score: 0
Accepted
time: 176ms
memory: 10464kb
input:
1 9 704116 877292 5
output:
704116
result:
ok 1 number(s): "704116"
Test #11:
score: 0
Accepted
time: 0ms
memory: 5676kb
input:
1 3 820703 814856 86
output:
820703
result:
ok 1 number(s): "820703"
Test #12:
score: -100
Wrong Answer
time: 0ms
memory: 3636kb
input:
1 29 195626 207042 54
output:
0
result:
wrong answer 1st numbers differ - expected: '195626', found: '0'