結果

問題 No.3204 Permuted Integer
ユーザー Brandon Li
提出日時 2025-07-25 12:43:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 784 bytes
コンパイル時間 2,536 ms
コンパイル使用メモリ 201,756 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-07-25 12:43:09
合計ジャッジ時間 8,408 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other TLE * 1 -- * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
#ifdef LOCAL
#include <debug.h>
#else
#define dbg(...) 0
#define dbgn(...) 0
#endif

void solve(){
	int n; 
	cin >> n; 
	vector<int> v; 
	while(n){
		v.push_back(n % 10); 
		n /= 10; 
	}
	sort(v.begin(), v.end()); 
	do{
		int ans = 0, f = -1; 
		for(int i = v.size() - 1; i >= 0; i--){
			if(v[i] != 0 && f == -1) {
				f = i; 
			}
			ans += v[i] * pow(10, i); 
		}
		int rt = sqrt(ans); 
		if(rt * rt == ans){
			for(int i = f; i >= 0; i--){
				cout << v[i]; 
			}
			cout << '\n'; 
			return; 
		}
	} while(next_permutation(v.begin(), v.end())); 
	cout << -1 << '\n'; 
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    int tt; 
    cin >> tt; 
    while(tt--){
        solve(); 
    }
    return 0; 
}
0