QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#550331#2481. PickpocketsXfJbUhpyzgaW#WA 0ms3908kbC++141.4kb2024-09-07 11:38:042024-09-07 11:38:04

Judging History

你现在查看的是最新测评结果

  • [2024-09-07 11:38:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3908kb
  • [2024-09-07 11:38:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int>> q;
int a[100005],l[20],c[20],val[1<<16],sum[1<<16],f[1<<16],g[1<<16];
int n,m;
int main(){
    // freopen("h.in","r",stdin);
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;++i) scanf("%d",&a[i]);
    for (int h=1;h<=m;++h){
        int t=0;
        for (int i=1;i<=n;++i)
            if (a[i]>=h) ++t;
            else{
                q.emplace(t);
                if (q.size()>m) q.pop();
                t=0;
            }
        if (t){
            q.emplace(t);
            if (q.size()>m) q.pop();
            t=0;
        }
    }
    for (int i=1;i<=m;++i) scanf("%d%d",&l[i],&c[i]);
    for (int s=0;s<(1<<m);++s){
        for (int i=1;i<=m;++i)
            if (s&(1<<i-1)) sum[s]+=l[i],val[s]+=c[i];
    }
    for (int s=0;s<(1<<m);++s) f[s]=-1e8;
    f[0]=0;
    while (!q.empty()){
        int L=q.top();q.pop();
        for (int s=0;s<(1<<m);++s) g[s]=f[s];
        for (int s=0;s<(1<<m);++s)
            if (f[s]>=0){
                int T=((1<<m)-1)^s;
                for (int t=T;t;t=(t-1)&T)
                    if (sum[t]<=L)
                        g[s|t]=max(g[s|t],f[s]+val[t]);
            }
        for (int s=0;s<(1<<m);++s) f[s]=g[s];
    }
    int ans=0;
    for (int s=0;s<(1<<m);++s) ans=max(ans,f[s]);
    printf("%d\n",ans);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3904kb

input:

2 2
1 2
1 5
2 5

output:

10

result:

ok single line: '10'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3908kb

input:

2 2
1 2
2 5
1 5

output:

10

result:

ok single line: '10'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3892kb

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: 3776kb

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: 3820kb

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: 3892kb

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: 3796kb

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'