QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#593382#5303. No Bug No GameIron_gainerCompile Error//C++202.8kb2024-09-27 13:38:502024-09-27 13:38:51

Judging History

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

  • [2024-09-27 13:38:51]
  • 评测
  • [2024-09-27 13:38:50]
  • 提交

answer

#include<iostream>
#include<vector>
#include<array>
#include<climits>
#include<random>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int, int> pii;
constexpr int inf = 1e9;
void solve()
{
	int n, k;
	cin >> n >> k;
	vector<vector<array<int, 2>>>dp(n + 1, vector<array<int, 2>>(k + 1, { -inf, -inf }));
	vector<array<int, 11>>v(n + 1);
	ll sum = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> v[i][0];
		for (int j = 1; j <= v[i][0]; j++)
		{
			cin >> v[i][j];
		}
		sum += v[i][v[i][0]];
	}
	if (sum <= k)
	{
		cout << sum << endl;
		return;
	}
	dp[0][0][0] = 0;
	dp[0][0][1] = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= k; j++)
		{
			dp[i][j][0] = dp[i - 1][j][0];	 
			dp[i][j][1] = dp[i - 1][j][1];
			if (j >= v[i][0])
			{
				dp[i][j][0] = max(dp[i - 1][j - v[i][0]][0] + v[i][v[i][0]], dp[i-1][j][0]);
				dp[i][j][1] = max(dp[i - 1][j - v[i][0]][1] + v[i][v[i][0]], dp[i-1][j][1]);
			}
			for (int k = 1; k < v[i][0] && j >= k; k++)
			{
				dp[i][j][1] = max(dp[i - 1][j - k][0] + v[i][k], dp[i][j][1]);
			}	
		}
	}
	cout << max(dp[n][k][1],dp[n][k][0]) << endl;
}
void speed()
{
	ios::sync_with_stdio(0);
	cin.tie(0);                                                                                          
	cout.tie(0);
}
int main()
{
	speed();
	int t;
	//cin >> t;
	t = 1;
	while (t--)
	{
		solve();
	}
	return 0;
}
typedef unsigned int ui;
typedef pair<int, int> pii;
constexpr int inf = 1e9;
void solve()
{
	int n, k;
	cin >> n >> k;
	vector<vector<array<int, 2>>>dp(n + 1, vector<array<int, 2>>(k + 1, { -inf, -inf }));
	vector<array<int, 11>>v(n + 1);
	ll sum = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> v[i][0];
		for (int j = 1; j <= v[i][0]; j++)
		{
			cin >> v[i][j];
		}
		sum += v[i][v[i][0]];
	}
	if (sum <= k)
	{
		cout << sum << endl;
		return;
	}
	dp[0][0][0] = 0;
	dp[0][0][1] = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= k; j++)
		{
			dp[i][j][0] = dp[i - 1][j][0];	 
			dp[i][j][1] = dp[i - 1][j][1];
			if (j >= v[i][0])
			{
				dp[i][j][0] = max(dp[i - 1][j - v[i][0]][0] + v[i][v[i][0]], dp[i][j][0]);
				dp[i][j][1] = max(dp[i - 1][j - v[i][0]][1] + v[i][v[i][0]], dp[i][j][1]);
			}
			for (int k = 1; k < v[i][0] && j >= k; k++)
			{
				dp[i][j][1] = max(dp[i - 1][j - k][1] + v[i][k], dp[i][j][1]);
			}
		}
	}
	cout << max(dp[n][k][1],dp[n][k][0]) << endl;
}
void speed()
{
	ios::sync_with_stdio(0);
	cin.tie(0);                                                                                          
	cout.tie(0);
}
int main()
{
	speed();
	int t;
	//cin >> t;
	t = 1;
	while (t--)
	{
		solve();
	}
	return 0;
}

Details

answer.code:77:15: error: redefinition of ‘constexpr const int inf’
   77 | constexpr int inf = 1e9;
      |               ^~~
answer.code:14:15: note: ‘constexpr const int inf’ previously defined here
   14 | constexpr int inf = 1e9;
      |               ^~~
answer.code:78:6: error: redefinition of ‘void solve()’
   78 | void solve()
      |      ^~~~~
answer.code:15:6: note: ‘void solve()’ previously defined here
   15 | void solve()
      |      ^~~~~
answer.code:120:6: error: redefinition of ‘void speed()’
  120 | void speed()
      |      ^~~~~
answer.code:57:6: note: ‘void speed()’ previously defined here
   57 | void speed()
      |      ^~~~~
answer.code:126:5: error: redefinition of ‘int main()’
  126 | int main()
      |     ^~~~
answer.code:63:5: note: ‘int main()’ previously defined here
   63 | int main()
      |     ^~~~