結果
| 問題 |
No.326 あみだますたー
|
| コンテスト | |
| ユーザー |
kongarishisyamo
|
| 提出日時 | 2016-03-17 13:27:15 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| コード長 | 756 bytes |
| コンパイル時間 | 674 ms |
| コンパイル使用メモリ | 61,140 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-07 23:27:58 |
| 合計ジャッジ時間 | 1,892 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 26 |
ソースコード
#include<iostream>
#include<vector>
using namespace std;
vector<int> L;
vector<int> R;
int amida_to(int n){
for(int i=0;i<L.size();i++){
if(L[i]==n) n=R[i];
else if(R[i]==n) n=L[i];
}
return n;
}
#define NMAX 100
int main(){
int N,K,X,Y,A[NMAX];
int NM;
cin>>N;
cin>>K;
NM=N;
for(int i=0;i<K;i++){
cin>>X>>Y;
L.push_back(X);
R.push_back(Y);
}
for(int i=0;i<N;i++){
cin>>A[i];
}
while(NM!=0){
int ii;
for(ii=0;;ii++){
if(A[ii]==NM) break;
}
int to=amida_to(ii+1);
while(to>NM){
L.push_back(to-1);
R.push_back(to);
to--;
}
while(to<NM){
L.push_back(to);
R.push_back(to+1);
to++;
}
NM--;
}
cout<<L.size()-K<<endl;
for(int i=K;i<L.size();i++){
cout<<L[i]<<" "<<R[i]<<endl;
}
}
kongarishisyamo