結果
| 問題 | No.3775 Distant Swap |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-23 21:25:54 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 10 ms / 2,000 ms |
| + 362µs | |
| コード長 | 581 bytes |
| 記録 | |
| コンパイル時間 | 2,695 ms |
| コンパイル使用メモリ | 339,072 KB |
| 実行使用メモリ | 9,900 KB |
| 最終ジャッジ日時 | 2026-10-23 21:26:00 |
| 合計ジャッジ時間 | 5,562 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge3_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(nullptr);
int N, K; cin >> N >> K;
vector<int> P(N);
for (int i = 0; i < N; i++) {
cin >> P[i];
if (P[i] % K != (i + 1) % K) {
cout << "-1\n";
return 0;
}
}
vector<pair<int, int>> ans;
for (int i = 0; i < N; i++) {
for (int j = K; j < N; j++) {
if (P[j] < P[j - K]) {
ans.push_back({j - K, j});
swap(P[j], P[j - K]);
}
}
}
cout << ans.size() << '\n';
for (auto [l, r]: ans) {
cout << l + 1 << ' ' << r + 1 << '\n';
}
}