結果

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

ソースコード

diff #

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

vector<int> trans(ll n)
{
  vector<int> v(10, 0);
  while (n > 0)
  {
    v[n % 10]++;
    n /= 10;
  }
  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);
    int k = p[0];
    for (int j = 0; j <= k; j++)
    {
      p[0] = j;
      if (mp.count(p) == 1)
      {
        cout << mp[p] << "\n";
        p[0] = -1000;
        j = k + 10;
      }
    }
    if (p[0] > -50)
      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