CSES - HIIT Open 2024 - Results
Submission details
Task:Equilateral numbers
Sender:Sold days
Submission time:2024-11-16 13:10:27 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:15:17: error: reference to 'numbers' is ambiguous
   15 |                 numbers[i] = (i + 1) * (i + 2) / 2;
      |                 ^~~~~~~
In file included from /usr/include/c++/11/bits/max_size_type.h:37,
                 from /usr/include/c++/11/bits/ranges_base.h:38,
                 from /usr/include/c++/11/string_view:48,
                 from /usr/include/c++/11/bits/basic_string.h:48,
                 from /usr/include/c++/11/string:55,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 f...

Code

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MAX_LEN = 1e6 + 1234;

ll numbers[MAX_LEN];

signed main() {
	ll n;
	cin >> n;

	for (ll i = 0; i < MAX_LEN; i++) {
		numbers[i] = (i + 1) * (i + 2) / 2;
	}

	for (ll i = 0; i < MAX_LEN; i++) {
		if (numbers[i] == n) {
			cout << 1 << '\n';
			return 0;
		}
	}

	for (ll i = 0; i < MAX_LEN; i++) {
		if (numbers[i] > n) break;
		auto it = lower_bound(numbers, numbers + MAX_LEN, n - numbers[i]);
		if ((numbers[i] + *it) == n) {
			cout << 2 << '\n';
			return 0;
		}
	}

	cout << 3 << '\n';

	return 0;
}