QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202815#2481. Pickpocketsnameless_story#WA 0ms3824kbC++201.2kb2023-10-06 13:34:462023-10-06 13:34:46

Judging History

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

  • [2023-10-06 13:34:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2023-10-06 13:34:46]
  • 提交

answer

#include"bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(),(x).end()
template<class T1,class T2> bool cmin(T1 &x,const T2 &y) { if (y<x) { x=y; return 1; }return 0; }
template<class T1,class T2> bool cmax(T1 &x,const T2 &y) { if (x<y) { x=y; return 1; }return 0; }
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n,m,i,j;
	cin>>m>>n;
	vector<int> a(m);
	vector<int> len;
	function<void(int,int)> dfs=[&](int l,int r)
		{
			if (l>=r||len.size()>n) return;
			len.push_back(r-l);
			int i;
			for (i=l; i<r; i++) --a[i];
			for (i=l; i<r; i++) if (a[i])
			{
				l=i;
				while (i<r&&a[i]) ++i;
				dfs(l,i);
				l=i;
			}
		};
	for (int &x:a) cin>>x;
	dfs(0,m);
	if (len.size()>n)
	{
		cout<<"0\n";
		return 0;
	}
	vector<int> l(n),w(n);
	for (i=0; i<n; i++) cin>>l[i]>>w[i];
	m=1<<n;
	vector<int> f(m,-1e9);
	f[0]=0;
	vector<int> s1(m),s2(m);
	for (i=0; i<m; i++) for (j=0; j<n; j++)
	{
		s1[i]+=(i>>j&1)*l[j];
		s2[i]+=(i>>j&1)*w[j];
	}
	for (int x:len)
	{
		// cerr<<x<<endl;
		vector<int> g(m,-1e9);
		for (i=0; i<m; i++) for (j=i; j; j=j-1&i) if (s1[j]==x) cmax(g[i],f[i^j]+s2[j]);
		swap(f,g);
	}
	cout<<max(0,*max_element(all(f)))<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 2
1 2
1 5
2 5

output:

10

result:

ok single line: '10'

Test #2:

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

input:

2 2
1 2
2 5
1 5

output:

10

result:

ok single line: '10'

Test #3:

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

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

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

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

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: 0
Accepted
time: 0ms
memory: 3592kb

input:

3 6
2 1 1
2 1
3 5
2 3
3 3
2 4
3 3

output:

0

result:

ok single line: '0'

Test #8:

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

input:

2 5
1 1
1 5
2 4
1 4
2 2
1 1

output:

9

result:

ok single line: '9'

Test #9:

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

input:

1 2
1
1 5
1 4

output:

5

result:

ok single line: '5'

Test #10:

score: -100
Wrong Answer
time: 0ms
memory: 3480kb

input:

2 4
0 1
1 6
2 2
2 5
2 5

output:

0

result:

wrong answer 1st lines differ - expected: '6', found: '0'