結果
| 問題 |
No.397 NO MORE KADOMATSU
|
| コンテスト | |
| ユーザー |
ant2357
|
| 提出日時 | 2017-08-24 00:17:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 58 ms / 2,000 ms |
| コード長 | 649 bytes |
| コンパイル時間 | 2,010 ms |
| コンパイル使用メモリ | 198,984 KB |
| 最終ジャッジ日時 | 2025-01-05 02:27:29 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
#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;
}
ant2357