QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#550287#2481. PickpocketsXfJbUhpyzgaW#WA 0ms3720kbC++141.3kb2024-09-07 11:19:142024-09-07 11:19:14

Judging History

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

  • [2024-09-07 11:19:14]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3720kb
  • [2024-09-07 11:19:14]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long 
#define N 100005
#define P 167772161
#define GC getchar()
#define PC putchar
using namespace std;
ll re(){
	ll s=0,b=1; char c=GC;
	while(c>'9'||c<'0'){if(c=='-')b=-b; c=GC;}
	while(c<='9'&&c>='0'){s=(s<<1)+(s<<3)+(c^48); c=GC;}
	return s*b;
}
void ks(ll s){if(s<0)PC('-'),s=-s; if(s>=10)ks(s/10); PC((s%10)|48);}
int n,m,h[N],a[N],s,cd[17],jz[17],su[1<<16],sjz[1<<16],an;
bool dp[17][1<<16];
priority_queue<int,vector<int>,greater<int> >q;
int main(){
	n=re(),m=re();
	for(int i=1; i<=n; ++i)h[i]=min(re(),1ll*m);
	for(int i=1; i<=n; ++i){
		while(h[i]){
			int le=0,j=i;
			while(h[j]&&j<=n){
				h[j]--; j++; le++;
			}
			q.push(le);
			if(q.size()>m)q.pop();
		}
	}
	while(!q.empty()){a[++s]=q.top(); q.pop();}
	for(int i=0; i<m; ++i){cd[i]=re(); jz[i]=re();}
	for(int i=1; i<(1<<m); ++i)
	 for(int j=0; j<m; ++j)
	  if(i&(1<<j)){su[i]=su[i^(1<<j)]+cd[j]; sjz[i]=sjz[i^(1<<j)]+jz[j]; break;}
	dp[0][0]=1;
	for(int i=1; i<=s; ++i){
		for(int j=0; j<(1<<m); ++j){
			if(!dp[i-1][j])continue;
			int os=((1<<m)-1)^j; dp[i][j]=1;
			for(int k=os; k; k=(k-1)&os)
			 if(su[k]<=a[i])dp[i][j|k]=1;
		}
		//for(int j=0; j<(1<<m); ++j)cout<<dp[i][j]; cout<<endl;
	}
	for(int i=0; i<(1<<m); ++i)
	 if(dp[s][i])an=max(an,sjz[i]);
	ks(an);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 2
1 2
1 5
2 5

output:

10

result:

ok single line: '10'

Test #2:

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

input:

2 2
1 2
2 5
1 5

output:

10

result:

ok single line: '10'

Test #3:

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

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

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

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

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

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'