QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203127#2481. Pickpocketswhsyhyyh#WA 1ms4128kbC++141.6kb2023-10-06 15:37:362023-10-06 15:37:37

Judging History

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

  • [2023-10-06 15:37:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4128kb
  • [2023-10-06 15:37:36]
  • 提交

answer

#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize(3)
#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],f[(1<<16)+5],vis[(1<<16)+5];
int sum[(1<<16)+5];
int st[N],top;
bool cmp(int x,int y) {
	return x>y;
}
void DP(int i,int all) {
	memset(vis,0,sizeof(vis));
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	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;
			}
		}
	}
	drep(S,(1<<m)-1,0) if(f[S]) {
		int S_=((1<<m)-1)^S;
		for(int s=S_;s;s=(s-1)&(S_)) if(dp[s]) {
			f[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)+5) rep(i,1,m) sum[S]+=(S>>(i-1)&1)*tim[i];
	f[0]=1;
	rep(i,1,m) {
		top=0;
		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(i,min(top,m));
	}
	int ans=0;
	rep(S,0,(1<<16)-1) if(f[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: 1ms
memory: 4004kb

input:

2 2
1 2
1 5
2 5

output:

10

result:

ok single line: '10'

Test #2:

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

input:

2 2
1 2
2 5
1 5

output:

10

result:

ok single line: '10'

Test #3:

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

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

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

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

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

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'