QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203318 | #2481. Pickpockets | whsyhyyh# | WA | 1ms | 5972kb | C++14 | 1.2kb | 2023-10-06 16:46:18 | 2023-10-06 16:46:19 |
Judging History
answer
#include<bits/stdc++.h>
#define N 100010
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define drep(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int rd() {
int res=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f*=-1;ch=getchar();}
while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
return res*f;
}
int n,m,a[N],tim[N],val[N];
bool dp[(1<<16)+5],vis[(1<<16)+5];
int sum[(1<<16)+5];
int st[N*16],top;
bool cmp(int x,int y) {
return x>y;
}
void DP(int all) {
rep(j,1,all) {
drep(S,(1<<m)-1,0) if(dp[S]&&!vis[S]) {
//vis[S]=1;
int S_=((1<<m)-1)^S;
for(int s=S_;s;s=(s-1)&(S_)) {
if(sum[s]<=st[j]) dp[S|s]=1;
}
}
}
}
int main() {
n=rd(),m=rd();
rep(i,1,n) a[i]=rd();
rep(i,1,m) tim[i]=rd(),val[i]=rd();
rep(S,0,(1<<m)-1) rep(i,1,m) sum[S]+=(S>>(i-1)&1)*tim[i];
dp[0]=1;
rep(i,1,m) {
for(int j=1,k;j<=n;j=k+1) {
k=j;
if(a[j]<i) continue;
while(k<n&&a[k+1]>=i) k++;
st[++top]=k-j+1;
}
}
sort(st+1,st+top+1,cmp);
DP(min(top,m));
int ans=0;
rep(S,0,(1<<m)-1) if(dp[S]) {
int res=0;
rep(j,1,m) res+=(S>>(j-1)&1)*val[j];
ans=max(ans,res);
}
printf("%d",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3876kb
input:
2 2 1 2 1 5 2 5
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5964kb
input:
2 2 1 2 2 5 1 5
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3756kb
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: 5788kb
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: 5972kb
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: 1ms
memory: 5784kb
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: 1ms
memory: 5932kb
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'