結果

問題 No.3204 Permuted Integer
ユーザー miho-4
提出日時 2025-07-18 21:35:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 587 ms / 2,000 ms
コード長 469 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 93,188 KB
最終ジャッジ日時 2025-07-18 23:37:19
合計ジャッジ時間 12,827 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

D=defaultdict(lambda:[10**9]*10)
for i in range(1,10**5):
  if 10**9<i*i:
    break
  s=str(i*i)
  cnt=[0]*10
  for e in s:
    e=int(e)
    cnt[e]+=1
  t=tuple(cnt[1:])
  for id in range(cnt[0],10):
    D[t][id]=min(D[t][id],i*i)

test=int(input())
for _ in range(test):
  s=str(input())
  cnt=[0]*10
  for e in s:
    e=int(e)
    cnt[e]+=1
  t=tuple(cnt[1:])
  if D[t][cnt[0]]<10**9:
    print(D[t][cnt[0]])
  else:
    print(-1)
0