結果
| 問題 | No.3775 Distant Swap |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-23 22:23:50 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 10 ms / 2,000 ms |
| + 521µs | |
| コード長 | 1,061 bytes |
| 記録 | |
| コンパイル時間 | 2,938 ms |
| コンパイル使用メモリ | 343,876 KB |
| 実行使用メモリ | 9,824 KB |
| 最終ジャッジ日時 | 2026-10-23 22:24:23 |
| 合計ジャッジ時間 | 4,954 ms |
|
ジャッジサーバーID (参考情報) |
judge6_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)
template <class T> bool chmin(T& x, T y) {
return x > y ? (x = y, true) : false;
}
template <class T> bool chmax(T& x, T y) {
return x < y ? (x = y, true) : false;
}
void solve() {
int n, k;
cin >> n >> k;
vector<int> p(n);
rep(i, 0, n) cin >> p[i], p[i]--;
vector<vector<int>> v(k);
rep(i, 0, n) v[i % k].push_back(p[i]);
vector<pair<int, int>> ans;
rep(i, 0, k) {
int f = 0;
for(int x : v[i]) if(x % k != i) f = 1;
if(f) {
cout << "-1\n";
return;
}
int m = v[i].size();
rep(lp, 0, m) rep(j, 0, m - 1) {
if(v[i][j] > v[i][j + 1]) {
swap(v[i][j], v[i][j + 1]);
ans.push_back({j * k + i, j * k + i + k});
}
}
}
cout << ans.size() << '\n';
for(auto [x, y] : ans) {
cout << x + 1 << ' ' << y + 1 << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int t = 1;
// cin >> t;
while (t--) solve();
}