結果

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

ソースコード

diff #

from collections import defaultdict

t = int(input())
d = defaultdict(lambda: float('inf'))
for i in range(1, 100000):
    s = str(i*i)
    l = [0]*10
    for c in s:
        l[int(c)] += 1
    d[tuple(l)] = min(d[tuple(l)], i)
for _ in range(t):
    n = int(input())
    lis = [0]*10
    for c in str(n):
        lis[int(c)] += 1
    ans = float('inf')
    for i in range(lis[0]+1):
        lis2 = [i]+lis[1:]
        if tuple(lis2) in d:
            ans = min(ans, d[tuple(lis2)])
    if ans == float('inf'):
        print(-1)
    else:
        print(ans*ans)
0