結果
| 問題 | No.3775 Distant Swap |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-23 21:35:10 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 855 bytes |
| 記録 | |
| コンパイル時間 | 1,830 ms |
| コンパイル使用メモリ | 201,380 KB |
| 実行使用メモリ | 9,908 KB |
| 最終ジャッジ日時 | 2026-10-23 21:35:36 |
| 合計ジャッジ時間 | 4,670 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 6 |
コンパイルメッセージ
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 a=0;a<z;a++) {
int mn=a;
for (int b=a+1;b<z;b++)
if (p[b*k+r]<p[mn*k+r]) mn=b;
if (mn==a) continue;
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;
}