結果

問題 No.2449 square_permutation
ユーザー FromBooskaFromBooska
提出日時 2023-09-01 09:30:45
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 815 bytes
コンパイル時間 493 ms
コンパイル使用メモリ 87,340 KB
実行使用メモリ 82,372 KB
最終ジャッジ日時 2023-09-01 09:30:51
合計ジャッジ時間 5,307 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
76,272 KB
testcase_01 AC 68 ms
71,892 KB
testcase_02 AC 71 ms
71,720 KB
testcase_03 AC 70 ms
71,684 KB
testcase_04 AC 77 ms
76,660 KB
testcase_05 AC 102 ms
77,580 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 辞書順なので前から確定していくか
# idxに対して、一番大きくて平方数になる数を探して場所をスワップ
# nの倍数だけをサーチすると4と9が交換できず失敗する
# 全探索では間に合わないだろう。。。困ったな

N = int(input())
pos = [-1]*(N+1)
for n in range(1, N+1):
    if n > N/2 and pos[n] == -1:
        pos[n] = n
        continue
    
    mx = N-N%n
    #print('n', n, 'mx', mx)
    # 倍数だけのサーチではダメだ、4が9と交換できない
    for j in range(mx, n-1, -1):
        #print('n', n, 'j', j, (n*j)**0.5, ((n*j)**0.5).is_integer())
        if pos[j] == -1 and ((n*j)**0.5).is_integer() == True:
            pos[n] = j
            pos[j] = n
            break
    #print('n', n, 'pos', pos)
print(*pos[1:])  
0