結果

問題 No.326 あみだますたー
ユーザー ttakanottakano
提出日時 2017-12-03 10:33:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,003 bytes
コンパイル時間 1,616 ms
コンパイル使用メモリ 147,412 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 22:39:23
合計ジャッジ時間 3,582 ms
ジャッジサーバーID
(参考情報)
judge9 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int main(){
  int n,k;
  cin>>n;
  cin>>k;
  int x[6002];
  int y[6002];
  REP(i,k)cin>>x[i]>>y[i];
  int a[102];
  rep(i,1,n+1)cin>>a[i];
  int g[102];
  rep(i,1,n+1){rep(j,1,n+1){if(a[j]==i)g[i]=j;}}
  int s[102];
  rep(i,0,n+1)s[i]=i;
  REP(i,k)swap(s[x[i]],s[y[i]]);
  //printall(n+1,s);
  vector<int> v;
  rep(i,1,n+1){
    rep(j,i+1,n+1){
      if(g[i]==s[j]){
        for(int k=j;k>1;k--){
          v.push_back(k-1);
          swap(s[k],s[k-1]);
          //printall(n+1,s);
          if(g[i]==s[i])break;
        }
      }
      if(g[i]==s[i])break;
    }
  }
  print(v.size());
  REP(i,v.size())print(v[i]<<" "<<v[i]+1);
}
0