結果

問題 No.3204 Permuted Integer
ユーザー norioc
提出日時 2025-07-18 21:49:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 464 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 82,284 KB
実行使用メモリ 78,132 KB
最終ジャッジ日時 2025-07-18 21:49:34
合計ジャッジ時間 8,621 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import count

LIMIT = 10**9


def f(n: int) -> int:
    ds = sorted([int(c) for c in str(n)])
    res = 0
    for d in ds:
        res = 10*res + d

    return res


d = {}
for i in count(1):
    x = i*i
    if x > LIMIT: break

    y = f(x)
    if y not in d:
        d[y] = x


def solve():
    N = int(input())
    x = f(N)
    if x in d:
        return d[x]

    return -1



T = int(input())
for _ in range(T):
    res = solve()
    print(res)
0