QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#90962#6130. Plants vs. Zombieszzh00195Compile Error//C++14895b2023-03-26 10:48:482023-03-26 10:48:50

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-26 10:48:50]
  • 评测
  • [2023-03-26 10:48:48]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;
const int N = 1e5 + 10;

ll a[N], n, m;
ll b[N];

bool check(ll x)
{
	ll cnt = 0;
	memset(B, 0, sizeof(long long) * (n + 3));
	for (int i = 1; i <= n; i ++ )
	{
		ll t = x - b[i];
		if (t <= 0)
		{
			cnt ++ ;
			continue;
		}
		ll res = t / a[i];
		if (t % a[i])	res ++ ;
		cnt += res * 2 - 1;
		b[i + 1] += a[i + 1] * (res - 1);
		if (cnt > m)	return false;
	}
	return true;
}

void solve()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i ++ )
	{
		cin >> a[i];
		b[i] = 0;
	}
	ll l = 0, r = 1e18, mid;
	while (l < r)
	{
		mid = l + r + 1 >> 1;
		if (check(mid))	l = mid;
		else r = mid - 1;
	}
	cout << l << endl;
}

int main()
{
	int t;
	cin >> t;
	while (t -- )
	{
		solve();
	}
	return 0;
}

Details

answer.code: In function ‘bool check(ll)’:
answer.code:17:16: error: ‘B’ was not declared in this scope
   17 |         memset(B, 0, sizeof(long long) * (n + 3));
      |                ^