結果

問題 No.3204 Permuted Integer
コンテスト
ユーザー Rumain831
提出日時 2026-09-12 15:30:17
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 602 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,374 ms
コンパイル使用メモリ 185,224 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2026-09-12 15:30:27
合計ジャッジ時間 8,572 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 5 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<array>
#include<map>
#include<algorithm>
using namespace std;
using ll = long long;
using ar = array<int, 10>;

ar f(ll n){
  ar ans;
  while(n){
    ans[n%10]++;
    n/=10;
  }
  return ans;
}

int main(void){
  map<ar, ll> mi;
  for(ll i=1; i*i<=1e10; i++){
    ar now=f(i*i);
    if(mi.count(now)==0) mi[now]=i*i;
  }
  int t; cin >> t;
  while(t--){
    ll n; cin >> n;
    ar now=f(n);
    ll ans=1e18;
    while(now[0]>=0){
      if(mi.count(now)) ans=min(ans, mi[now]);
      now[0]--;
    }
    cout << (ans==1e18?-1:ans) << '\n';
  }
  return 0; 
}
0