結果

問題 No.397 NO MORE KADOMATSU
コンテスト
ユーザー 梧桐
提出日時 2026-03-22 17:28:35
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 719 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 419 ms
コンパイル使用メモリ 80,520 KB
実行使用メモリ 28,988 KB
平均クエリ数 32.50
最終ジャッジ日時 2026-03-22 17:28:39
合計ジャッジ時間 2,922 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef pair<int, int> PII;

const int N = 110;

int n, a[N], ans;
vector<PII> moves;

int main() {
    // freopen("no.in", "r", stdin);
    // freopen("no.out", "w", stdout);

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);

    for (int i = 2; i <= n - 1; ++i) {
        if ((a[i - 1] > a[i] && a[i] < a[i + 1]) || (a[i - 1] < a[i] && a[i] > a[i + 1])) {
            ++ans;
            moves.push_back({ i, i + 1 });
            swap(a[i], a[i + 1]);
        }
    }

    printf("%d\n", ans);
    for (int i = 0; i < ans; ++i) {
        printf("%d %d\n", moves[i].first, moves[i].second);
    }

    return 0;
}
0