結果
| 問題 |
No.397 NO MORE KADOMATSU
|
| コンテスト | |
| ユーザー |
dgd1724
|
| 提出日時 | 2016-11-08 18:35:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 49 ms / 2,000 ms |
| コード長 | 1,046 bytes |
| コンパイル時間 | 1,270 ms |
| コンパイル使用メモリ | 163,396 KB |
| 実行使用メモリ | 25,220 KB |
| 平均クエリ数 | 936.56 |
| 最終ジャッジ日時 | 2024-07-17 00:36:25 |
| 合計ジャッジ時間 | 2,890 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
#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;
}
dgd1724