結果
問題 | No.326 あみだますたー |
ユーザー |
![]() |
提出日時 | 2015-12-19 00:25:59 |
言語 | C++11 (gcc 11.4.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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 9 ms
5,376 KB |
testcase_09 | AC | 10 ms
5,376 KB |
testcase_10 | AC | 10 ms
5,376 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
ソースコード
#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; }