結果

問題 No.3204 Permuted Integer
ユーザー forest3
提出日時 2025-07-23 13:26:46
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 671 bytes
コンパイル時間 2,131 ms
コンパイル使用メモリ 178,424 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2025-07-23 13:26:57
合計ジャッジ時間 10,051 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, a, n) for(int i = a; i < n; i++)

int main() {
	int T;
	cin >> T;
	map<string, vector<int>> mp;
	ll n = 1e10;
	for(ll i = 1; i * i < n; i++) {
		int sq = i * i;
		string s = to_string(sq);
		sort(s.begin(), s.end());
		while(*s.begin() == '0') s.erase(s.begin());
		mp[s].push_back(sq);
	}
	for(auto it = mp.begin(); it != mp.end(); it++) {
		sort(it->second.begin(), it->second.end());
	}
	rep(ti, 0, T) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		while(*s.begin() == '0') s.erase(s.begin());
		if(mp.count(s)) cout << mp[s][0] << endl;
		else cout << -1 << endl; 
	}

}

	
0