結果
| 問題 | No.3775 Distant Swap |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-23 21:40:56 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 174 ms / 2,000 ms |
| + 697µs | |
| コード長 | 835 bytes |
| 記録 | |
| コンパイル時間 | 3,202 ms |
| コンパイル使用メモリ | 200,364 KB |
| 実行使用メモリ | 9,900 KB |
| 最終ジャッジ日時 | 2026-10-23 21:41:26 |
| 合計ジャッジ時間 | 6,453 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main() {
| ^~~~
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
using namespace std;
main() {
int n,k;
cin>>n>>k;
int p[n];
for (int i=0;i<n;i++)
cin>>p[i];
vector <pair<int,int>> ans;
for (int r=0;r<k;r++) {
int z=0;
while ((z*k)+r<n) z++;
for (int jj=0;jj<z;jj++)
for (int a=0;a<z-1;a++) {
int mn=a+1;
if (p[mn*k+r]<p[a*k+r]) {
ans.push_back(make_pair(a*k+r, mn*k+r));
swap(p[a*k+r], p[mn*k+r]);
}
}
}
bool yes=true;
for (int i=1;i<n;i++)
if (p[i]<=p[i-1]) yes=false;
if (yes) {
cout<<ans.size()<<endl;
for (auto x : ans)
cout<<x.first+1<<" "<<x.second+1<<endl;
} else cout<<-1<<endl;
}