結果
| 問題 |
No.326 あみだますたー
|
| コンテスト | |
| ユーザー |
Lay_ec
|
| 提出日時 | 2015-12-19 00:25:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,233 bytes |
| コンパイル時間 | 902 ms |
| コンパイル使用メモリ | 90,056 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-16 08:47:16 |
| 合計ジャッジ時間 | 4,447 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 |
| other | AC * 7 WA * 19 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
vector<int> a(n),tar(n);
for(int i=0;i<n;i++) a[i]=i+1;
for(int i=0;i<k;i++){
int x,y;
cin>>x>>y;
swap(a[x-1],a[y-1]);
}
for(int i=0;i<n;i++) cin>>tar[i];
vector<pair<int,int> > ans;
for(int i=0;i<n;i++){
if(tar[i]==a[i]) continue;
int pos=0;
for(int j=1;j<n;j++){
if(tar[i]==a[j]){
pos=j;
break;
}
}
int x=i;
for(int j=pos;j+1<=x;j++){
ans.push_back(make_pair(j+1,j+1+1));
swap(a[j],a[j+1]);
}
for(int j=pos;j-1>=x;j--){
ans.push_back(make_pair(j-1+1,j+1));
swap(a[j-1],a[j]);
}
}
cout<<ans.size()<<endl;
for(int i=0;i<ans.size();i++) cout<<ans[i].first<<" "<<ans[i].second<<endl;
return 0;
}
Lay_ec