結果

問題 No.397 NO MORE KADOMATSU
ユーザー dgd1724dgd1724
提出日時 2016-11-08 18:35:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,046 bytes
コンパイル時間 1,101 ms
コンパイル使用メモリ 147,476 KB
実行使用メモリ 24,324 KB
平均クエリ数 936.56
最終ジャッジ日時 2023-09-24 00:41:36
合計ジャッジ時間 2,696 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
23,520 KB
testcase_01 AC 20 ms
23,748 KB
testcase_02 AC 19 ms
23,340 KB
testcase_03 AC 20 ms
23,340 KB
testcase_04 AC 19 ms
23,340 KB
testcase_05 AC 26 ms
24,312 KB
testcase_06 AC 26 ms
23,736 KB
testcase_07 AC 24 ms
24,324 KB
testcase_08 AC 26 ms
23,808 KB
testcase_09 AC 22 ms
23,532 KB
testcase_10 AC 42 ms
23,340 KB
testcase_11 AC 20 ms
23,760 KB
testcase_12 AC 27 ms
23,340 KB
testcase_13 AC 36 ms
24,024 KB
testcase_14 AC 33 ms
24,312 KB
testcase_15 AC 34 ms
23,604 KB
testcase_16 AC 20 ms
23,760 KB
testcase_17 AC 19 ms
23,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

//const static double	de_PI	= 3.14159265358979323846;
//const static int	de_MOD	= 1000000007;
//const static int	de_MAX	= 999999999;
//const static int	de_MIN = -999999999;

int main(void) {

	//std::ifstream inf("123.txt");	std::cin.rdbuf(inf.rdbuf());

	int N = 0, M = 0;
	std::cin >> N;
	std::vector<int> A(N),B;
	for (int i = 0; i < N; i++) { std::cin >> A[i]; }

	int st = 0, ed = N - 1, next = 0;
	while(1) {

		next = st;
		for (int i = st; i < ed; i++) {
			if (A[i] > A[i + 1]) {
				M++;
				B.push_back(i);
				B.push_back(i + 1);
				std::swap(A[i], A[i + 1]);
				next = i;
			}
		}

		ed = next;
		if (st == ed) { break; }

		next = ed;
		for (int i = ed; i > st; i--) {
			if (A[i] < A[i - 1]) {
				M++;
				B.push_back(i - 1);
				B.push_back(i);
				std::swap(A[i], A[i - 1]);
				next = i;
			}
		}

		st = next;
		if (st == ed) { break; }
	}

	std::cout << M << std::endl;
	for (unsigned int i = 0; i < B.size(); i += 2) {
		std::cout << B[i] << " " << B[i + 1] << std::endl;
	}

	std::cin >> N;

}

0