結果

問題 No.3183 Swap or Rotate
ユーザー iastm
提出日時 2025-07-11 12:06:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 644 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 102,348 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-07-11 12:06:24
合計ジャッジ時間 2,638 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int N;
    std::cin >> N;
    std::vector<int> P(N);
    for (int &p : P) std::cin >> p;
    auto sorted = [&]() {
        for (int i = 0; i < N; i++) {
            if (P[i] != i) return false;
        }
        return true;
    };
    while (!sorted()) {
        if (P[0] == 0 && P[1] == N - 1 || P[0] > P[1] && !(P[0] == N - 1 && P[1] == 0)) {
            std::swap(P[0], P[1]);
            std::cout << 'S';
        } else {
            P.push_back(P[0]);
            P.erase(P.begin());
            std::cout << 'R';
        }
    }
    std::cout << std::endl;
}
0