結果

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

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef long double ld;
#define sz(c) ((ll)(c).size())
#define ALL(x) x.begin(),x.end()
#define LB(A,x) (ll)(lower_bound(ALL(A),x)-A.begin())
#define UB(A,x) (ll)(upper_bound(ALL(A),x)-A.begin())
#define BS(A,x) binary_search(ALL(A),x)
#define rep(i,a,b) for(int i=a;i<b;i++)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl =vector<ll>;
using vvl=vector<vl>;
const long long mod=998244353;
//using mint = modint998244353;
int main() { 
	map<vi,ll>mp;
	for(ll i=1;i*i<1e10;i++){
	vi A;
	ll N=i*i;
	while(N){A.push_back(N%10);N/=10;}
	sort(ALL(A));
	reverse(ALL(A));
	//while(A.back()==0)A.pop_back();
	if(mp[A]==0)mp[A]=i*i;
	}
	int tt;cin>>tt;
	while(tt--){
		ll n;cin>>n;
		vi B;
		while(n){B.push_back(n%10);n/=10;}
		sort(ALL(B));
		reverse(ALL(B));
		//while(B.back()==0)B.pop_back();
		//rep(i,0,sz(B))cout<<B[i]<<" \n"[i==sz(B)-1];
		ll ans=1e18;
		if(mp[B]!=0)ans=mp[B];
	    while(B.back()==0){B.pop_back();if(mp[B]!=0)chmin(ans,mp[B]);}
		if(ans!=1e18)cout<<ans<<endl;
		else cout<<-1<<endl;
	}
}
0