QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#203003 | #2481. Pickpockets | SolitaryDream# | RE | 2ms | 12048kb | C++17 | 1.6kb | 2023-10-06 14:34:10 | 2023-10-06 14:34:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1e3+7;
int h,t;
int c[N];
int v[N],w[N],sv[1<<16],sw[1<<16];
int f[1<<16];
vector<int> con;
int sd[N*16];
int main()
{
scanf("%d%d",&h,&t);
for(int i=1;i<=h;i++)
{
scanf("%d",&c[i]);
if(c[i]>t)
{
puts("0");
return 0;
}
}
for(int i=0;i<t;i++)
scanf("%d%d",&v[i],&w[i]);
for(int S=0;S<(1<<t);S++)
for(int i=0;i<t;i++)
if(S>>i&1)
sv[S]+=v[i],sw[S]+=w[i];
for(int d=1;d<=t;d++)
{
int s=0;
for(int i=1;i<=h;i++)
{
if(c[i]>=d)
s++;
else
{
if(s)
{
con.push_back(s);
s=0;
}
}
}
if(s)
con.push_back(s);
}
if(con.size()>t)
{
puts("0");
return 0;
}
memset(sd,-1,sizeof(sd));
int ps=0;
sd[0]=0;
for(int i=0;i<con.size();i++)
{
ps+=con[i];
sd[ps]=i+1;
}
f[0]=1;
for(int S=0;S<(1<<t)-1;S++)
{
if(sd[sv[S]]==-1||!f[S])
continue;
int o=sd[sv[S]];
for(int T=S;;T=(T+1)|S)
{
int W=T^S;
if(sv[W]==con[o])
f[T]=1;
if(T==(1<<t)-1)
break;
}
}
int ans=0;
for(int S=0;S<(1<<t);S++)
if(sv[S]==ps&&f[S])
ans=max(ans,sw[S]);
printf("%d\n",ans);
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 12048kb
input:
2 2 1 2 1 5 2 5
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 1ms
memory: 10456kb
input:
2 2 1 2 2 5 1 5
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 0ms
memory: 11944kb
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: 1ms
memory: 10416kb
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: 1ms
memory: 10532kb
input:
1 5 1 1 2 1 1 1 2 1 5 1 2
output:
5
result:
ok single line: '5'
Test #6:
score: -100
Runtime Error
input:
1 7 0 1 5 1 5 1 5 1 2 1 5 1 3 1 6