結果

問題 No.326 あみだますたー
ユーザー ふっぴーふっぴー
提出日時 2017-09-02 12:01:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,798 bytes
コンパイル時間 1,484 ms
コンパイル使用メモリ 168,188 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 10:53:20
合計ジャッジ時間 2,634 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 7 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
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 9 ms
5,376 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 10 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 7 ms
5,376 KB
testcase_24 AC 6 ms
5,376 KB
testcase_25 AC 7 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 6 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:58:33: warning: 'start' may be used uninitialized [-Wmaybe-uninitialized]
   58 |                 start = b[start - 1];
      |                           ~~~~~~^~~
main.cpp:51:21: note: 'start' was declared here
   51 |                 int start;
      |                     ^~~~~

ソースコード

diff #

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };


int main() {
	int n, k, i, j;
	cin >> n >> k;
	vi x(k), y(k);
	for (i = 0; i < k; i++) {
		cin >> x[i] >> y[i];
	}
	vi a(n);
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	vi b(n);
	for (i = 1; i <= n; i++) {
		int temp = i;
		for (j = 0; j < k; j++) {
			if (x[j] == temp)
				temp = y[j];
			else if (y[j] == temp)
				temp = x[j];
		}
		b[i - 1] = temp;
	}
	vi x2, y2;
	int goal, x_last = 0;
	for (goal = 1; goal <= n; goal++) {
		int start;
		for (i = 0; i < n; i++) {
			if (a[i] == goal) {
				start = i + 1;
				break;
			}
		}
		start = b[start - 1];
		if (start > goal) {
			for (i = start; i > goal; i--) {
				x2.push_back(i - 1);
				y2.push_back(i);
			}
		}
		else if (start < goal) {
			for (i = start; i < goal; i++) {
				x2.push_back(i);
				y2.push_back(i + 1);
			}
		}
		vi c = b;
		for (i = 1; i <= n; i++) {
			int temp = c[i-1];
			for (j = x_last; j < x2.size(); j++) {
				if (x2[j] == temp)
					temp = y2[j];
				else if (y2[j] == temp)
					temp = x2[j];
			}
			b[i - 1] = temp;
		}
		x_last = x2.size();
	}
	cout << x_last << endl;
	for (i = 0; i < x_last; i++) {
		cout << x2[i] << " " << y2[i] << endl;
	}
}
0