結果

問題 No.2449 square_permutation
ユーザー FromBooskaFromBooska
提出日時 2023-09-01 11:47:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 779 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 87,260 KB
実行使用メモリ 93,928 KB
最終ジャッジ日時 2023-09-01 11:47:33
合計ジャッジ時間 6,010 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,444 KB
testcase_01 AC 68 ms
71,328 KB
testcase_02 AC 82 ms
71,512 KB
testcase_03 AC 67 ms
71,164 KB
testcase_04 AC 69 ms
71,428 KB
testcase_05 AC 81 ms
76,836 KB
testcase_06 AC 108 ms
82,524 KB
testcase_07 AC 113 ms
83,532 KB
testcase_08 AC 121 ms
84,080 KB
testcase_09 AC 111 ms
85,108 KB
testcase_10 AC 123 ms
88,396 KB
testcase_11 AC 131 ms
89,332 KB
testcase_12 AC 135 ms
90,160 KB
testcase_13 AC 148 ms
93,844 KB
testcase_14 AC 147 ms
93,780 KB
testcase_15 AC 145 ms
93,804 KB
testcase_16 AC 140 ms
93,800 KB
testcase_17 AC 139 ms
93,788 KB
testcase_18 AC 134 ms
92,344 KB
testcase_19 AC 138 ms
93,552 KB
testcase_20 AC 140 ms
93,544 KB
testcase_21 AC 142 ms
93,928 KB
testcase_22 AC 67 ms
71,368 KB
testcase_23 AC 138 ms
93,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 辞書順なので前から確定していく
# nに平方数をかけていきNまでで使われていない数をリストアップ
# その次が自力思い浮かばず
# 候補の数の最初と最後、次と最後から2番目、、をマッチングさせてスワップする

N = int(input())
pos = [-1]*(N+1)
for n in range(1, N+1):
    if pos[n] != -1:
        continue
    
    if n > N/2 and pos[n] == -1:
        pos[n] = n
        continue
    candidates = []
    for j in range(1, N+1):
        if n*j*j > N:
            break
        if pos[n*j*j] == -1:
            candidates.append(n*j*j)
    L = len(candidates)
    for l in range(L):
        pos[candidates[l]] = candidates[L-l-1]
    #print('n', n, 'candidates', candidates, 'pos', pos)
print(*pos[1:])
0