結果

問題 No.3204 Permuted Integer
ユーザー noshinn
提出日時 2025-06-09 09:23:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 715 bytes
コンパイル時間 1,790 ms
コンパイル使用メモリ 207,412 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-07-18 20:50:32
合計ジャッジ時間 4,017 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<int> trans(ll n)
{
  vector<int> v(10);
  while (n > 0)
  {
    v[n % 10]++;
    n /= 10;
  }
  v[0] = 0;
  return v;
}

void solve()
{
  int n;
  cin >> n;
  map<vector<int>, ll> mp;
  for (ll i = 0; i < 1e5; i++)
  {
    if ((i * i) > 1e9)
      break;
    auto p = trans(i * i);
    mp.insert({p, i * i});
  }
  for (int i = 0; i < n; i++)
  {
    ll num;
    cin >> num;
    auto p = trans(num);
    if (mp.count(p) == 1)
      cout << mp[p] << "\n";
    else
      cout << "-1\n";
  }
}

int main()
{
  cin.tie(0)->sync_with_stdio(0);
  cout << fixed << setprecision(20);
  int CNT = 1;
  for (int i = 0; i < CNT; i++)
    solve();
}
0