QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#228808#5822. 城市建设TerryjoyCompile Error//C++14894b2023-10-28 14:16:382023-10-28 14:16:38

Judging History

This is the latest submission verdict.

  • [2023-10-28 14:16:38]
  • Judged
  • [2023-10-28 14:16:38]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i <= (b); i++)
#define drep(i, a, b) for (int i = a; i >= (b); i--)
typedef long long ll;
int n, c;
ll ccc(int x) {
	return (1ll * x * x - x % 2) / 4;
}
ll cal(int num) {
	int a = n / num, b = a + 1, cb = n % num, ca = num - cb;
	ll tot;
	if (num == 1)
		tot = 0;
	else {
		tot = n - 1;
		if (cb >= 2) {
			tot -= 2 * (b / 2);
		} else if (cb == 1) {
			tot -= b / 2 + a / 2;
		} else
			tot -= 2 * (a / 2);
	}
	return tot + 1ll * num * c + ccc(a) * ca + ccc(b) * cb;
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> c;
	int l = 1, r = n;
	for (int i = 1; i <= 100; ++i) {
		int lm = l + (r - l) / 3, rm = r - (r - l) / 3;
		if (cal(lm) < cal(rm))
			r = rm;
		else
			l = lm;
	}
	ll ans = 1e18;
	ans = min(ans, cal(i)) 
	cout << ans;
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:40:28: error: ‘i’ was not declared in this scope
   40 |         ans = min(ans, cal(i))
      |                            ^