結果

問題 No.3204 Permuted Integer
ユーザー elphe
提出日時 2025-07-18 23:08:27
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 809 bytes
コンパイル時間 1,124 ms
コンパイル使用メモリ 102,532 KB
実行使用メモリ 11,040 KB
最終ジャッジ日時 2025-07-18 23:08:32
合計ジャッジ時間 5,131 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other TLE * 1 -- * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>

static inline constexpr bool check(const uint_fast32_t target) noexcept
{
	uint_fast32_t l = 0, r = UINT32_C(1) << 15;
	while (l + 1 < r)
	{
		const auto c = (l + r) >> 1;
		if (c * c <= target) l = c;
		else r = c;
	}

	return (l * l == target);
}

static inline constexpr int_fast32_t solve(std::string& N) noexcept
{
	std::sort(N.begin(), N.end());
	do
	{
		const auto target = std::stoull(N);
		if (check(target))
			return target;
	}
	while (std::next_permutation(N.begin(), N.end()));

	return -1;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios::sync_with_stdio(false);
	
	uint_fast32_t T, i;
	std::cin >> T;
	for (i = 0; i != T; ++i)
	{
		std::string N;
		std::cin >> N;
		std::cout << solve(N) << '\n';
	}

	return 0;
}
0