結果

問題 No.366 ロボットソート
コンテスト
ユーザー Zhan1794
提出日時 2026-02-10 17:25:35
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 917 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,996 ms
コンパイル使用メモリ 213,896 KB
実行使用メモリ 16,324 KB
最終ジャッジ日時 2026-02-10 17:25:41
合計ジャッジ時間 6,010 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 7 RE * 2 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

#define int long long

#define all(v) (v).begin(), (v).end()
#define bit(mask, i) (((mask) >> (i)) & 1)
#define debug(x) #x << " = " << x

typedef long long ll;
typedef long double ld;

const int N = 300 + 5;

int n, a[N], k;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // freopen("input.inp", "r", stdin);
    // freopen("output.out", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    cin >> k;
    int ans = 0;
    for (int it = 1; it <= 6666; it++) {
        if (is_sorted(a + 1, a + n + 1)) {
            break;
        }
        for (int i = n - k; i >= 1; i--) {
            if (a[i] > a[i + k]) {
                swap(a[i], a[i + k]);
                ans++;
            }
        }
    }
    if (!is_sorted(a + 1, a + n + 1)) {
        ans = -1;
    }
    cout << ans << '\n';
    return 0;
}
0