結果

問題 No.3775 Distant Swap
コンテスト
ユーザー Jimmy Skhirtladze
提出日時 2026-10-23 21:40:56
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 174 ms / 2,000 ms
+ 697µs
コード長 835 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,202 ms
コンパイル使用メモリ 200,364 KB
実行使用メモリ 9,900 KB
最終ジャッジ日時 2026-10-23 21:41:26
合計ジャッジ時間 6,453 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main() {
      | ^~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
using namespace std;

main() {
    int n,k;
    cin>>n>>k;
    int p[n];
    for (int i=0;i<n;i++)
        cin>>p[i];

    vector <pair<int,int>> ans;
    for (int r=0;r<k;r++) {

        int z=0;
        while ((z*k)+r<n) z++;

        for (int jj=0;jj<z;jj++)
        for (int a=0;a<z-1;a++) {
            int mn=a+1;
            if (p[mn*k+r]<p[a*k+r]) {
                ans.push_back(make_pair(a*k+r, mn*k+r));
                swap(p[a*k+r], p[mn*k+r]);
            }
        }
    }

    bool yes=true;
    for (int i=1;i<n;i++)
        if (p[i]<=p[i-1]) yes=false;

    if (yes) {
        cout<<ans.size()<<endl;
        for (auto x : ans)
            cout<<x.first+1<<" "<<x.second+1<<endl;
    } else cout<<-1<<endl;
}
0