結果

問題 No.3204 Permuted Integer
コンテスト
ユーザー koheijkt
提出日時 2026-04-28 10:46:47
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 641 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 172 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 84,992 KB
最終ジャッジ日時 2026-04-28 10:46:55
合計ジャッジ時間 7,434 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# 10**9 までの平方数を洗い出す
pattern = {}
# pattern[(1, 0, 2, 3, 1, 3, ...)] = 平方数


for i in range(1, 10**5):
    x = i*i
    if x > 10**9:
        break

    cnt = [0] * 9 # 1 ~ 9 の個数
    for s in str(x):
        if s != '0':
            cnt[int(s) - 1] += 1
    t = tuple(cnt)
    # 最小のものだけ
    if t not in pattern:
        pattern[t] = x

#print(pattern)

T = int(input())
for i in range(T):
    N = input()
    cnt = [0] * 9
    for s in str(N):
        if s != '0':
            cnt[int(s) - 1] += 1
    t = tuple(cnt)

    if t in pattern:
        print(pattern[t])
    else:
        print('-1')
0