結果

問題 No.3775 Distant Swap
コンテスト
ユーザー hiro1729
提出日時 2026-10-23 21:25:54
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 10 ms / 2,000 ms
+ 362µs
コード長 581 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 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
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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';
	}
}
0