結果

問題 No.366 ロボットソート
コンテスト
ユーザー Zhan1794
提出日時 2026-02-10 16:32:50
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 1,041 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,855 ms
コンパイル使用メモリ 213,516 KB
実行使用メモリ 16,328 KB
最終ジャッジ日時 2026-02-10 16:32:57
合計ジャッジ時間 6,443 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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 <= 6000; it++) {
        if (is_sorted(a + 1, a + n + 1)) {
            // cout << it << '\n';
            break;
        }
        for (int i = 1; i + k <= n; i++) {
            if (a[i] > a[i + k]) {
                swap(a[i], a[i + k]);
                ans++;
            }
        }
    }
    if (!is_sorted(a + 1, a + n + 1)) {
        ans = -1;
    }
    // for (int i = 1; i <= n; i++) {
    //     cout << a[i] << " \n"[i == n];
    // }
    cout << ans << '\n';
    return 0;
}
0