結果

問題 No.3204 Permuted Integer
ユーザー otoshigo
提出日時 2025-07-25 20:56:18
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,371 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 14,204 KB
最終ジャッジ日時 2025-07-25 20:56:47
合計ジャッジ時間 27,665 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
d = defaultdict(int)
T = int(input())
se = set()
def num_sort(x):
    li = []
    for c in str(x):
        li.append(int(c))
    li.sort()
    li = li[::-1]
    ret = 0
    for i in li:
        ret = 10 * ret + i
    return ret
for n in range(1, 10 ** 5):
    val = num_sort(n * n)
    if val not in d:
        d[val] = n * n
    else:
        d[val] = min(d[val], n * n)
for _ in range(T):
    N = input()
    val = num_sort(N)
    ans = -1
    while True:
        if val in d:
            if ans == -1:
                ans = d[val]
            else:
                ans = min(ans, d[val])
        if val % 10 != 0:
            break
        val /= 10
    print(ans)
0