結果

問題 No.3204 Permuted Integer
ユーザー alcea
提出日時 2025-07-18 21:28:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 571 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 209,244 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-07-18 23:35:21
合計ジャッジ時間 6,577 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
  map<string,int> mp;
  for(int i=1;i*i<=1000000000;i++){
    string tmp=to_string(i*i);
    sort(tmp.begin(),tmp.end());
    if(mp.count(tmp));
    else mp[tmp]=i*i;
  }
  int t;
  cin>>t;
  while(t--){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    int n=s.size();
    int ans=2e9;
    for(int i=0;i<n;i++){
      if(i==0||s[i-1]=='0'){
        //cerr<<s.substr(i)<<endl;
        if(mp.count(s.substr(i))) ans=min(ans,mp[s.substr(i)]);
      }
    }
    if(ans>1e9) ans=-1;
    cout<<ans<<endl;
  }
}
0