結果
問題 |
No.2449 square_permutation
|
ユーザー |
![]() |
提出日時 | 2023-09-01 10:25:21 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,095 bytes |
コンパイル時間 | 607 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 169,728 KB |
最終ジャッジ日時 | 2025-01-03 06:27:10 |
合計ジャッジ時間 | 41,511 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 1 WA * 9 TLE * 11 |
ソースコード
# 辞書順なので前から確定していくか # 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 if (n**0.5).is_integer() == True: # 倍数だけのサーチではダメだ、4が9と交換できない for j in range(N, 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) else: mx = N-N%n for j in range(mx, n-1, -n): #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:])