結果

問題 No.326 あみだますたー
ユーザー beetbeet
提出日時 2019-04-19 15:19:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 2,389 ms
コンパイル使用メモリ 206,340 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 17:34:16
合計ジャッジ時間 4,018 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 7 ms
4,348 KB
testcase_04 AC 6 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 9 ms
4,348 KB
testcase_09 AC 11 ms
4,348 KB
testcase_10 AC 12 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 7 ms
4,348 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 6 ms
4,348 KB
testcase_23 AC 7 ms
4,348 KB
testcase_24 AC 7 ms
4,348 KB
testcase_25 AC 7 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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]=a[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]);
        swap(p[i],p[i+1]);
        flg=1;
        break;
      }
    }
    if(flg) continue;
    break;
  }
  
  for(int i=0;i<n;i++) assert(r[i]==p[i]);
  
  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