結果

問題 No.3204 Permuted Integer
コンテスト
ユーザー norioc
提出日時 2025-07-19 12:58:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 599 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 82,672 KB
実行使用メモリ 81,928 KB
最終ジャッジ日時 2025-07-19 12:58:44
合計ジャッジ時間 11,455 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import count

LIMIT = 10**9


def f(n: int) -> list[str]:
    s = ''.join(sorted(str(n)))
    res = [s]
    while len(s) > 1 and s[0] == '0':
        s = s[1:]
        res.append(s)

    return res


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

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


def solve():
    N = int(input())
    ans = INF
    for y in f(N):
        ans = min(ans, d.get(y, INF))

    if ans == INF:
        return -1
    return ans


INF = 1 << 60
T = int(input())
for _ in range(T):
    res = solve()
    print(res)
0