結果

問題 No.3204 Permuted Integer
ユーザー achapi
提出日時 2025-07-18 21:37:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 604 bytes
コンパイル時間 2,082 ms
コンパイル使用メモリ 209,252 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-07-18 23:37:10
合計ジャッジ時間 6,611 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	int t;
	cin >> t;
	map<string, int> mp;
	for (int i = 1; i * i <= 1e9; i++){
		string S = to_string(i * i);
		sort(S.rbegin(), S.rend());
		if (mp.count(S) == 0){
			mp[S] = i * i;
		}
	}
	while (t--)[&]{
		string N;
		cin >> N;
		int ans = 2e9;
		sort(N.rbegin(), N.rend());
		if (mp.count(N) > 0){
			ans = mp[N];
		}
		while (N.back() == '0'){
			N.pop_back();
			if (mp.count(N) > 0){
				ans = min(ans, mp[N]);
			}
		}
		if (ans == 2e9){
			ans = -1;
		}
		cout << ans << endl;
	}();
}
0