結果

問題 No.3775 Distant Swap
コンテスト
ユーザー GOTKAKO
提出日時 2026-10-24 00:39:04
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 12 ms / 2,000 ms
+ 678µs
コード長 552 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,481 ms
コンパイル使用メモリ 219,220 KB
実行使用メモリ 9,864 KB
最終ジャッジ日時 2026-10-24 00:39:11
合計ジャッジ時間 4,538 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,K; cin >> N >> K;
    vector<int> P(N);
    for(auto &p : P) cin >> p,p--;
    vector<pair<int,int>> answer;
    for(int t=0; t<N; t++){
        for(int i=0; i+K<N; i++) if(P.at(i) > P.at(i+K)) answer.push_back({i,i+K}),swap(P.at(i),P.at(i+K));
    }
    for(int i=0; i<N; i++) if(P.at(i) != i){cout << "-1\n"; return 0;}
    cout << answer.size() << "\n";
    for(auto [a,b] : answer) cout << a+1 << " " << b+1 << "\n";
}
0