QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#202999 | #2481. Pickpockets | SolitaryDream# | RE | 2ms | 11576kb | C++17 | 1.6kb | 2023-10-06 14:32:09 | 2023-10-06 14:32:09 |
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);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);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11224kb
input:
2 2 1 2 1 5 2 5
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 0ms
memory: 11572kb
input:
2 2 1 2 2 5 1 5
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 1ms
memory: 10524kb
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: 11044kb
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: 2ms
memory: 11576kb
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