結果

問題 No.397 NO MORE KADOMATSU
ユーザー kurenai3110kurenai3110
提出日時 2016-07-15 23:18:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 672 bytes
コンパイル時間 550 ms
コンパイル使用メモリ 71,600 KB
実行使用メモリ 24,360 KB
平均クエリ数 936.56
最終ジャッジ日時 2023-09-24 00:17:02
合計ジャッジ時間 1,983 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,640 KB
testcase_01 AC 20 ms
23,628 KB
testcase_02 AC 19 ms
23,652 KB
testcase_03 AC 23 ms
23,520 KB
testcase_04 AC 22 ms
24,324 KB
testcase_05 AC 21 ms
23,784 KB
testcase_06 AC 23 ms
24,276 KB
testcase_07 AC 22 ms
23,796 KB
testcase_08 AC 21 ms
23,532 KB
testcase_09 AC 19 ms
23,640 KB
testcase_10 AC 41 ms
23,796 KB
testcase_11 AC 19 ms
23,400 KB
testcase_12 AC 27 ms
23,652 KB
testcase_13 AC 31 ms
23,352 KB
testcase_14 AC 31 ms
23,616 KB
testcase_15 AC 34 ms
24,360 KB
testcase_16 AC 19 ms
23,652 KB
testcase_17 AC 20 ms
23,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int n;
vector<pair<int, int> > ans;

int bubblesort(vector<int> &a) {
	int cnt = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				ans.push_back(make_pair(j, j - 1));
				swap(a[j], a[j - 1]);
				flag = 1;
				cnt++;
			}
		}
	}
	return cnt;
}

int main() {
	vector<int> a;
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	cout << bubblesort(a) << endl;
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i].first << " " << ans[i].second << endl;
	}

	return 0;
}
0