結果

問題 No.3204 Permuted Integer
ユーザー Cecil
提出日時 2025-07-18 21:55:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 766 ms / 2,000 ms
コード長 621 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 82,040 KB
実行使用メモリ 110,684 KB
最終ジャッジ日時 2025-07-18 23:39:05
合計ジャッジ時間 14,473 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict as dd
dic = dd(lambda:-1)
for i in range(1, 10**5):
    val = i*i
    s = str(val)
    cnt = [0 for _ in range(10)]
    for j in range(len(s)):
        cnt[int(s[j])] += 1
    if dic[tuple(cnt)]!=-1:
        continue
    dic[tuple(cnt)] = val

T = int(input())
for _ in range(T):
    s = input()
    cnt = [0 for _ in range(10)]
    for j in range(len(s)):
        cnt[int(s[j])] += 1
    ans = -1
    if dic[tuple(cnt)]!=-1:
        ans = dic[tuple(cnt)]
    for j in range(cnt[0]):
        cnt[0] -= 1
        if dic[tuple(cnt)]!=-1:
            ans = dic[tuple(cnt)]
    print(ans)
0