QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#203129 | #2481. Pickpockets | Rd_rainydays# | WA | 1ms | 3860kb | C++20 | 1.6kb | 2023-10-06 15:39:52 | 2023-10-06 15:39:52 |
Judging History
answer
#include <bits/stdc++.h>
#define N 200005
#define M 20
using namespace std;
int n, m;
int a[N];
struct zero
{
int len, val;
friend bool operator<(zero a, zero b) { return a.len > b.len; }
} lib[M];
priority_queue<int, vector<int>, greater<int>> q;
int siz = 0, B;
int upper = 0;
int aux[M];
int ans = 0;
void dfs(int i, int s, int w) {
if (i == siz + 1) {
ans = std::max(ans, w);
return;
}
int tot = 0, vaild[M];
for (int j = 0; j < m; j++) if (s >> j & 1)
vaild[tot ++] = j;
for (int t = (1 << tot) - 1; t >= 0; t--) {
int len_s = 0;
int val_s = 0;
int sn = s;
for (int j = 0; j < tot && len_s <= aux[i]; j++) if (t >> j & 1) {
len_s += lib[vaild[j]].len;
val_s += lib[vaild[j]].val;
sn ^= (1 << vaild[j]);
}
if (len_s > aux[i]) continue;
dfs(i + 1, sn, w + val_s);
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
upper = max(upper, a[i]);
}
a[n + 1] = 0;
for (int u = 1; u <= min(upper, m); u++) {
int las = 0;
for (int i = 1; i <= n + 1; i++) if (a[i] < u) {
int nwlen = i - 1 - las;
if (siz == m) {
if (q.top() < nwlen)
q.pop(), q.push(nwlen);
} else {
siz++;
q.push(nwlen);
}
las = i;
}
}
for (int i = 1; i <= siz; i++)
{
aux[i] = q.top();
q.pop();
}
for (int i = 0; i < m; i++)
scanf("%d%d", &lib[i].len, &lib[i].val);
dfs(1, (1 << m) - 1, 0);
printf("%d\n", ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3860kb
input:
2 2 1 2 1 5 2 5
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
2 2 1 2 2 5 1 5
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
3 4 2 1 2 3 2 1 1 1 2 1 3
output:
7
result:
ok single line: '7'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
1 5 2 1 2 1 5 1 3 1 5 1 3
output:
10
result:
ok single line: '10'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
1 5 1 1 2 1 1 1 2 1 5 1 2
output:
5
result:
ok single line: '5'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
1 7 0 1 5 1 5 1 5 1 2 1 5 1 3 1 6
output:
0
result:
ok single line: '0'
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3608kb
input:
3 6 2 1 1 2 1 3 5 2 3 3 3 2 4 3 3
output:
5
result:
wrong answer 1st lines differ - expected: '0', found: '5'