結果

問題 No.1604 Swap Sort:ONE
ユーザー MineMine
提出日時 2021-09-10 17:53:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 398 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 87,028 KB
実行使用メモリ 76,728 KB
最終ジャッジ日時 2023-09-02 10:11:13
合計ジャッジ時間 5,399 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,340 KB
testcase_01 AC 70 ms
71,204 KB
testcase_02 AC 70 ms
71,364 KB
testcase_03 AC 72 ms
71,396 KB
testcase_04 AC 73 ms
71,392 KB
testcase_05 AC 78 ms
76,452 KB
testcase_06 AC 119 ms
76,524 KB
testcase_07 AC 127 ms
76,372 KB
testcase_08 AC 127 ms
76,176 KB
testcase_09 AC 125 ms
76,728 KB
testcase_10 AC 126 ms
76,532 KB
testcase_11 AC 128 ms
76,524 KB
testcase_12 AC 126 ms
76,184 KB
testcase_13 AC 127 ms
76,620 KB
testcase_14 AC 127 ms
76,384 KB
testcase_15 AC 126 ms
76,544 KB
testcase_16 AC 125 ms
76,232 KB
testcase_17 AC 95 ms
76,532 KB
testcase_18 AC 97 ms
76,424 KB
testcase_19 AC 121 ms
76,644 KB
testcase_20 AC 94 ms
76,472 KB
testcase_21 AC 124 ms
76,180 KB
testcase_22 AC 110 ms
76,604 KB
testcase_23 AC 84 ms
76,292 KB
testcase_24 AC 81 ms
75,964 KB
testcase_25 AC 124 ms
76,624 KB
testcase_26 AC 104 ms
76,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    n = int(input())
    p = list(map(int, input().split()))
    ans = 0
    flag = True
    while flag:
        flag = False
        for i in range(n-1):
            if p[i] > p[i+1]:
                p[i], p[i+1] = p[i+1], p[i]
                ans += 1
                flag = True

    for i in range(n-1):
        if p[i] == p[i+1]:
            return -1
    return ans

print(main())
0