結果
| 問題 | No.3775 Distant Swap |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-23 21:56:04 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 174 ms / 2,000 ms |
| + 189µs | |
| コード長 | 1,324 bytes |
| 記録 | |
| コンパイル時間 | 3,323 ms |
| コンパイル使用メモリ | 357,824 KB |
| 実行使用メモリ | 9,908 KB |
| 最終ジャッジ日時 | 2026-10-23 21:56:42 |
| 合計ジャッジ時間 | 6,412 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge6_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvl = vector<vll>;
using pll = pair<ll,ll>;
#define rep(i,N) for(ll i=0;i<N;++i)
#define rrep(i,N) for(ll i=N-1; i>=0; --i)
#define all(v) (v).begin(), (v).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N,K;cin >> N >> K;
vll P(N);
rep(i,N){
cin >> P[i];
--P[i];
}
ll j;
//入れ替えるのがmodK
rep(i,N){//
if(P[i]%K!=i%K){
cout << "-1\n";
return 0;
}
}
vector<pll> bubble;//どことどこを{x,y}
bool swapped;
rep(r,K){
swapped=true;
while(swapped){
swapped=false;
for(ll i=r;i<N-K;++i){
if(P[i]>P[i+K]){
swap(P[i],P[i+K]);
bubble.push_back({i+1,i+K+1});//1_indexed
swapped = true;
}
}
}
}
cout << bubble.size() << endl;
for(auto ans : bubble){
cout << ans.first << " " << ans.second << endl;
}
return 0;
}