結果

問題 No.3204 Permuted Integer
ユーザー forest3
提出日時 2025-07-23 15:38:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 710 bytes
コンパイル時間 1,625 ms
コンパイル使用メモリ 173,544 KB
実行使用メモリ 7,840 KB
最終ジャッジ日時 2025-07-23 15:38:17
合計ジャッジ時間 7,435 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 1
other RE * 26
権限があれば一括ダウンロードができます

ソースコード

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;
	ll n = 1e10;
	map<vector<int>, int> mp;
	for(ll i = 1; i * i < n; i++) {
		int sq = i * i;
		vector<int> c(10);
		while(sq) {
			int d = sq % 10;
			c[d]++;
			sq /= 10;
		}
		if(mp.count(c)) mp[c] = min(mp[c], sq);
		else mp[c] = sq;
	}
	rep(ti, 0, T) {
		int N;
		cin >> N;
		int INF = 1e9 + 1;
		vector<int> c(10);
		while(N) {
			int d = N % 10;
			c[d]++;
			N /= 10;
		}
		int ans = INF;
		int r = c[0] + 1;
		rep(i, 0, r) {
			if(mp.count(c)) {
				ans = min(ans, mp[c]);
				c[0]--;
			}
		}
		if(ans == INF) ans = -1;
		cout << ans << endl;
	}

}

	
0