結果

問題 No.3204 Permuted Integer
ユーザー detteiuu
提出日時 2025-07-18 21:30:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 386 ms / 2,000 ms
コード長 635 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 79,248 KB
最終ジャッジ日時 2025-07-18 23:36:34
合計ジャッジ時間 8,485 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

INF = 1<<60

D = defaultdict(lambda : (INF, INF))
for x in range(1, INF):
    if 10**9 < x**2:
        break
    X = str(x**2)
    SUM = 0
    cnt = 0
    for i in X:
        i = int(i)
        if i == 0:
            cnt += 1
        else:
            SUM += 10**(i-1)
    if cnt < D[SUM][0]:
        D[SUM] = (cnt, X)

for _ in range(int(input())):
    N = input()
    SUM = 0
    cnt = 0
    for n in N:
        n = int(n)
        if n == 0:
            cnt += 1
        else:
            SUM += 10**(n-1)
    if SUM in D and D[SUM][0] <= cnt:
        print(D[SUM][1])
    else:
        print(-1)
0