結果
| 問題 | No.3775 Distant Swap |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-23 21:26:51 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 9 ms / 2,000 ms |
| + 962µs | |
| コード長 | 620 bytes |
| 記録 | |
| コンパイル時間 | 2,214 ms |
| コンパイル使用メモリ | 339,340 KB |
| 実行使用メモリ | 9,916 KB |
| 最終ジャッジ日時 | 2026-10-23 21:26:56 |
| 合計ジャッジ時間 | 5,087 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> a(n);
for(auto &&v : a) cin >> v;
vector<pair<int,int>> ans;
for(int i = 0; i < k; i++){
for(int j = i; j < n; j += k){
for(int l = i; l + k < n; l += k){
if(a[l] > a[l + k]){
swap(a[l], a[l + k]);
ans.emplace_back(l + 1, l + 1 + k);
}
}
}
}
for(int i = 0; i + 1 < n; i++){
if(a[i] > a[i + 1]){
cout << "-1\n";
return 0;
}
}
cout << ans.size() << '\n';
for(auto &&[u, v] : ans) cout << u << ' ' << v << '\n';
}