結果

問題 No.326 あみだますたー
ユーザー kongarishisyamokongarishisyamo
提出日時 2016-03-17 13:21:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 625 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 61,852 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 16:42:22
合計ジャッジ時間 3,666 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}

int main(){

	int N,K,X,Y,A;

	cin>>N;
	cin>>K;

	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;
		int to=amida_to(i+1);
		while(to>A){
			L.push_back(to-1);
			R.push_back(to);
			to--;
		}
		while(to<A){
			L.push_back(to);
			R.push_back(to+1);
			to++;
		}
	}

	cout<<L.size()-K<<endl;
	for(int i=K;i<L.size();i++){
		cout<<L[i]<<" "<<R[i]<<endl;
	}
}

0