結果

問題 No.366 ロボットソート
ユーザー dazydazy
提出日時 2018-06-20 15:34:54
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 592 bytes
コンパイル時間 4,087 ms
コンパイル使用メモリ 131,488 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 10:50:00
合計ジャッジ時間 4,444 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 3 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:17:21: warning: variable 'ans' is uninitialized when used here [-Wuninitialized]
                    ans++;
                    ^~~
main.cpp:5:22: note: initialize the variable 'ans' to silence this warning
    int n, k, in, ans, i, j, l;
                     ^
                      = 0
1 warning generated.

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, k, in, ans, i, j, l;
    vector<int> a;
    cin >> n >> k;
    for(i=0; i<n; i++) {
        cin >> in;
        a.push_back(in);
    }
    for(i=0; i<k; i++) {
        for(l=((n-i-1)/k)*k+i; l>i; l-=k) {
            for(j=i; j<l; j+=k){
                if(a[j]>a[j+k]) {
                    swap(a[j], a[j+k]);
                    ans++;
                }
            }
        }
    }
    for(i=0; i<n-1; i++) {
        if(a[i]>a[i+1]) {
            ans = -1;
            break;
        }
    }
    printf("%d\n", ans);
}
0