結果

問題 No.3204 Permuted Integer
ユーザー eve__fuyuki
提出日時 2025-07-29 17:18:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 2,039 ms
コンパイル使用メモリ 204,936 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-07-29 17:18:09
合計ジャッジ時間 5,927 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

void fast_io() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
}

int main() {
	fast_io();
	map<string, int> mp;
	const int M = 1e9 + 5;
	for (int i = 1; i * i <= M; i++) {
		int num = i * i;
		string dig_cnt(10, '0');
		int tot = 0;
		while (num > 0) {
			dig_cnt[num % 10]++;
			num /= 10;
			tot++;
		}
		while (tot < 11) {
			if (mp.find(dig_cnt) == mp.end()) {
				mp[dig_cnt] = i * i;
			} else {
				mp[dig_cnt] = min(mp[dig_cnt], i * i);
			}
			dig_cnt[0]++;
			tot++;
		}
	}
	int t;
	cin >> t;
	for (; t--;) {
		int n;
		cin >> n;
		string dig_cnt(10, '0');
		while (n > 0) {
			dig_cnt[n % 10]++;
			n /= 10;
		}
		if (mp.count(dig_cnt)) {
			cout << mp[dig_cnt] << '\n';
		} else {
			cout << -1 << '\n';
		}
	}
}
0