結果

問題 No.397 NO MORE KADOMATSU
ユーザー kpinkcat
提出日時 2023-12-11 01:42:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,466 bytes
コンパイル時間 1,198 ms
コンパイル使用メモリ 111,636 KB
最終ジャッジ日時 2025-02-18 10:12:58
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>
#include<set>
#include<bitset>
#include<math.h>
#include<map>
#include<queue>
#include<iomanip>
using namespace std;
using ll = long long;

int main()
{
    int n, cnt = 0;
    cin >> n;
    vector<int> v(n);
    vector<vector<int>> ch;
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < n - 2; i++){
        for (int j = i; j < n-2; j++){
            if ((v[j] != v[j+1]) && (v[j] != v[j+2]) && (v[j+1] != v[j+2])){
                if (v[j+1] == max({v[j], v[j+1], v[j+2]})) {
                    swap(v[j+1], v[j+2]);
                    ch.push_back({j+1, j+2});
                    cnt++;
                    if (v[j] > v[j+1]){
                        swap(v[j], v[j+1]);
                        ch.push_back({j, j+1});
                        cnt++;
                    }
                else if ((v[j+1] == min({v[j], v[j+1], v[j+2]}))){
                    swap(v[j], v[j+1]);
                    ch.push_back({j, j+1});
                    cnt++;
                    if (v[j+1] > v[j+2]){
                        swap(v[j+1], v[j+2]);
                        ch.push_back({j+1, j+2});
                        cnt++;
                    }
                }
                }
            }
        }
    }
    cout << cnt << endl;
    for (auto x : ch){
        for (auto y1 : x){
            cout << y1 << " ";
        }
        cout << endl;
    }
    cin >> cnt;
}
0