結果

問題 No.3204 Permuted Integer
ユーザー karinohito
提出日時 2025-08-04 16:27:43
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 992 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 3,672 ms
コンパイル使用メモリ 289,068 KB
実行使用メモリ 16,256 KB
最終ジャッジ日時 2025-08-04 16:28:17
合計ジャッジ時間 29,774 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

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



int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll T;
    cin>>T;

    map<string,ll> M;
    for(ll a=1;a<=1e6;a++){
        ll d=a*a;
        string S=to_string(d);
        sort(S.begin(),S.end());
        reverse(S.begin(),S.end());
        if(!M.count(S))M[S]=d;
    }

    while(T--){
        ll N;
        cin>>N;
        string T=to_string(N);
        sort(T.begin(),T.end());
        ll an=1e18;
        reverse(T.begin(),T.end());
        while(T.back()=='0'){
            if(M.count(T))an=min(an,M[T]);
            T.pop_back();
        }
        if(M.count(T))an=min(an,M[T]);
        cout<<(an<1e17?an:-1)<<"\n";

    }
}
0