結果

問題 No.326 あみだますたー
ユーザー 0w10w1
提出日時 2016-11-28 17:56:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 875 bytes
コンパイル時間 1,822 ms
コンパイル使用メモリ 170,548 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-05 14:37:32
合計ジャッジ時間 5,752 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 8 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 9 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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

signed main(){
  int N; cin >> N;
  int K; cin >> K;
  vector< int > X( K ), Y( K );
  for( int i = 0; i < K; ++i )
    cin >> X[ i ] >> Y[ i ], --X[ i ], --Y[ i ];
  vector< int > A( N );
  for( int i = 0; i < N; ++i )
    cin >> A[ i ], --A[ i ];
  vector< int > cur( N );
  for( int i = 0; i < N; ++i )
    cur[ i ] = i;
  for( int i = 0; i < K; ++i )
    swap( cur[ X[ i ] ], cur[ Y[ i ] ] );
  vector< int > pri( N );
  for( int i = 0; i < N; ++i )
    pri[ A[ i ] ] = i;
  vector< int > mov;
  for( int i = 0; i < N; ++i )
    for( int j = 0; j + 1 < N - i; ++j )
      if( pri[ cur[ j ] ] > pri[ cur[ j + 1 ] ] )
        mov.push_back( j ),
        swap( cur[ j ], cur[ j + 1 ] );
  cout << mov.size() << endl;
  for( int i = 0; i < mov.size(); ++i )
    cout << mov[ i ] + 1 << " " << mov[ i ] + 2 << endl;
  return 0;
}
0