結果

問題 No.3204 Permuted Integer
コンテスト
ユーザー otoshigo
提出日時 2025-07-25 20:56:18
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 857 ms / 2,000 ms
+ 957µs
コード長 703 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 287 ms
コンパイル使用メモリ 21,408 KB
実行使用メモリ 18,968 KB
最終ジャッジ日時 2026-07-13 11:52:12
合計ジャッジ時間 19,005 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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