結果
問題 |
No.1854 Limited Bubble Sort
|
ユーザー |
|
提出日時 | 2022-02-26 18:25:13 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,009 bytes |
コンパイル時間 | 775 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 14,976 KB |
最終ジャッジ日時 | 2024-07-04 14:48:47 |
合計ジャッジ時間 | 17,316 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 WA * 13 |
ソースコード
def main(): T = int(input()) for i in range(T): N = int(input()) p = [0] + list(map(int, input().split())) + [N+1] m = [0 for i in range(N+2)] for i in range(1, N+2): m[i] = max(m[i-1], p[i]) ans = [] def swap(i): if i == p[i] or i+1 == p[i+1]: return False if i+1 == p[i] and max(m[i-1], p[i+1]) != i: return False if i == p[i+1] and m[i-1] != i-1: return False ans.append(i) p[i], p[i+1] = p[i+1], p[i] m[i] = max(m[i-1], p[i]) m[i+1] = max(m[i], p[i+1]) return True while True: for i in range(1, N): if p[i] > p[i+1] and swap(i): break else: break if p == sorted(p): print(len(ans)) print(*ans) else: print(-1) if __name__ == '__main__': main()