結果

問題 No.397 NO MORE KADOMATSU
ユーザー ant2357ant2357
提出日時 2017-08-24 00:17:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 649 bytes
コンパイル時間 2,010 ms
コンパイル使用メモリ 203,704 KB
実行使用メモリ 24,312 KB
平均クエリ数 936.56
最終ジャッジ日時 2023-09-24 01:31:22
合計ジャッジ時間 3,708 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
23,640 KB
testcase_01 AC 24 ms
23,616 KB
testcase_02 AC 23 ms
24,108 KB
testcase_03 AC 24 ms
23,388 KB
testcase_04 AC 24 ms
23,592 KB
testcase_05 AC 25 ms
23,364 KB
testcase_06 AC 26 ms
23,340 KB
testcase_07 AC 28 ms
23,640 KB
testcase_08 AC 23 ms
23,652 KB
testcase_09 AC 24 ms
24,120 KB
testcase_10 AC 53 ms
23,964 KB
testcase_11 AC 23 ms
24,216 KB
testcase_12 AC 32 ms
23,748 KB
testcase_13 AC 35 ms
23,412 KB
testcase_14 AC 37 ms
23,964 KB
testcase_15 AC 35 ms
23,364 KB
testcase_16 AC 24 ms
24,312 KB
testcase_17 AC 24 ms
23,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

vector<pair<int, int>> solve(int n, vector<int>& a) {
	vector<pair<int, int>> res;
	bool flag = true;
	for (int i = 0; flag; i++) {
		flag = false;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				res.push_back(make_pair(j - 1, j));
				flag = true;
			}
		}
	}

	return res;
}

int main() {
	int n;
	cin >> n;

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

	vector<pair<int, int>> res = solve(n, a);

	cout << res.size() << endl;
	for (auto p : res) {
		cout << p.first << " " << p.second << endl;
	}
	cout << flush;
	return 0;
}
0