QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#344489#2481. PickpocketsPetroTarnavskyi#RE 1ms3840kbC++201.6kb2024-03-04 17:44:412024-03-04 17:44:41

Judging History

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

  • [2024-03-04 17:44:41]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3840kb
  • [2024-03-04 17:44:41]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int INF = 1e9 + 47;

template<typename T>
void updMax(T& a, T b)
{
	a = max(a, b);
}

int getBit(int mask, int i)
{
	return (mask >> i) & 1;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h, t;
	cin >> h >> t;
	VI c(h);
	int maxC = 0;
	for (int& ci : c)
	{
		cin >> ci;
		maxC = max(maxC, ci);
	}
	if (maxC > t)
	{
		cout << "0\n";
		return 0;
	}
	vector<PII> a(t);
	for(auto& [d, income] : a)
		cin >> d >> income;
	VI vec;
	FOR(j, 1, maxC + 1)
	{
		int cur = 0;
		for (int ci : c)
		{
			if (j <= ci)
				cur++;
			else
			{
				if (cur != 0)
					vec.PB(cur);
				cur = 0;
			}
		}
		if (cur != 0)
			vec.PB(cur);
	}
	FOR(i, 1, SZ(vec))
		vec[i] += vec[i - 1];
	VI dp(1 << t, -INF);
	dp[0] = 0;
	int ans = 0;
	FOR(mask, 0, 1 << t)
	{
		if (dp[mask] < 0)
			continue;
		int sumMask = 0;
		FOR(i, 0, t)
			if (getBit(mask, i))
				sumMask += a[i].F;
		if (sumMask >= vec.back())
		{
			if (sumMask == vec.back())
				updMax(ans, dp[mask]);
			continue;
		}
		int ub = *upper_bound(ALL(vec), sumMask);
		FOR(i, 0, t)
		{
			if (!getBit(mask, i) && sumMask + a[i].F <= ub)
			{
				updMax(dp[mask | (1 << i)], dp[mask] + a[i].S);
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3604kb

input:

2 2
1 2
1 5
2 5

output:

10

result:

ok single line: '10'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3544kb

input:

2 2
1 2
2 5
1 5

output:

10

result:

ok single line: '10'

Test #3:

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

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

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

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

output:


result: