結果
| 問題 | No.3775 Distant Swap |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-24 01:54:59 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 26 ms / 2,000 ms |
| + 665µs | |
| コード長 | 791 bytes |
| 記録 | |
| コンパイル時間 | 1,533 ms |
| コンパイル使用メモリ | 191,344 KB |
| 実行使用メモリ | 9,856 KB |
| 最終ジャッジ日時 | 2026-10-24 01:55:12 |
| 合計ジャッジ時間 | 4,479 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
int n, k; cin >> n >> k;
vector<int> p(n), q(n);
for(auto&x:p) cin >> x;
vector<P> ans;
for(int i=0; i<k; i++){
vector<int> id, val;
for(int j=i; j<n; j+=k) id.push_back(j);
int m=id.size();
bool esc=true;
while(esc){
esc=false;
for(int j=0; j<m-1; j++){
if(p[id[j]]>p[id[j+1]]){
ans.emplace_back(id[j]+1, id[j+1]+1);
swap(p[id[j]], p[id[j+1]]);
esc=true; break;
}
}
}
}
q=p;
sort(begin(q), end(q));
if(p!=q) cout << -1 << endl;
else{
cout << ans.size() << endl;
for(auto [x, y]:ans) cout << x << ' ' << y << '\n';
}
return 0;
}