結果

問題 No.397 NO MORE KADOMATSU
ユーザー kurenai3110
提出日時 2016-07-15 23:18:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 672 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 70,944 KB
実行使用メモリ 25,220 KB
平均クエリ数 936.56
最終ジャッジ日時 2024-07-17 00:07:27
合計ジャッジ時間 2,416 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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