結果
| 問題 | 
                            No.3204 Permuted Integer
                             | 
                    
| コンテスト | |
| ユーザー | 
                             hiromi_ayase
                         | 
                    
| 提出日時 | 2025-07-18 21:49:44 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 215 ms / 2,000 ms | 
| コード長 | 952 bytes | 
| コンパイル時間 | 5,352 ms | 
| コンパイル使用メモリ | 335,612 KB | 
| 実行使用メモリ | 7,716 KB | 
| 最終ジャッジ日時 | 2025-07-18 23:38:37 | 
| 合計ジャッジ時間 | 10,088 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 26 | 
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define FAST_IO                \
  ios::sync_with_stdio(false); \
  cin.tie(0);
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;
int main() {
  FAST_IO
  map<string, int> mp;
  for (int i = 0; i * i <= 1e9 + 10; ++i) {
    string s = to_string(i * i);
    sort(s.begin(), s.end());
    if (mp.count(s) == 0 || mp[s] > i * i) {
      mp[s] = i * i;
    }
  }
  int T;
  cin >> T;
  while (T--) {
    string N;
    cin >> N;
    sort(N.begin(), N.end());
    int inf = 1e9 + 10;
    int mn = mp.count(N) ? mp[N] : inf;
    while (N.size() > 0 && N.front() == '0') {
      N.erase(N.begin());
      mn = min(mn, mp.count(N) ? mp[N] : inf);
    }
    if (mn == inf) {
      cout << -1 << endl;
    } else {
      cout << mn << endl;
    }
  }
}
            
            
            
        
            
hiromi_ayase