QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#228821#5822. 城市建设TerryjoyCompile Error//C++14954b2023-10-28 14:18:442023-10-28 14:18:44

Judging History

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

  • [2023-10-28 14:18:44]
  • 评测
  • [2023-10-28 14:18:44]
  • 提交

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;
	ll ans = 1e18;
	for (int i = 1; i <= 1000000; ++i) {
		int lm = l + (r - l) / 3, rm = r - (r - l) / 3;
		ans = min({ans, cal(lm), cal(rm)});
		if (cal(lm) < cal(rm))
			r = rm;
		else
			l = lm;
	}
	ll ans = 1e18;
	ans = min(ans, cal(l));
	cout << ans;
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:41:12: error: redeclaration of ‘ll ans’
   41 |         ll ans = 1e18;
      |            ^~~
answer.code:32:12: note: ‘ll ans’ previously declared here
   32 |         ll ans = 1e18;
      |            ^~~