結果

問題 No.326 あみだますたー
ユーザー beetbeet
提出日時 2019-04-19 14:57:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 969 bytes
コンパイル時間 2,524 ms
コンパイル使用メモリ 205,988 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-23 17:33:29
合計ジャッジ時間 7,014 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,372 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n,k;
  cin>>n>>k;
  vector<int> p(n);
  iota(p.begin(),p.end(),0);
  for(int i=0;i<k;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    swap(p[x],p[y]);
  }  
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];

  vector<int> r(n);
  for(int i=0;i<n;i++) r[p[i]]=i;

  vector<int> b(n);
  for(int i=0;i<n;i++) b[i]=r[a[i]];

  vector<int> xs,ys;
  while(1){
    int flg=0;
    for(int i=0;i+1<n;i++){
      if(b[i]>b[i+1]){
        xs.emplace_back(i);
        ys.emplace_back(i+1);
        swap(b[i],b[i+1]);
        flg=1;
        break;
      }
    }
    if(flg) continue;
    break;
  }
  
  int l=xs.size();
  cout<<l<<endl;
  for(int i=0;i<l;i++) cout<<xs[i]+1<<" "<<ys[i]+1<<endl;
  return 0;
}
0