結果

問題 No.326 あみだますたー
ユーザー beetbeet
提出日時 2019-04-19 15:00:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 997 bytes
コンパイル時間 2,381 ms
コンパイル使用メモリ 205,984 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-23 17:34:01
合計ジャッジ時間 6,126 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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],a[i]--;
  
  vector<int> r(n);
  for(int i=0;i<n;i++) r[a[i]]=i;

  vector<int> b(n);
  for(int i=0;i<n;i++) b[i]=r[p[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();
  assert(l<=6000);
  cout<<l<<endl;
  for(int i=0;i<l;i++) cout<<xs[i]+1<<" "<<ys[i]+1<<endl;
  return 0;
}
0