結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
  #include "settings/debug.cpp"
#else
  #define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int pos = 0;
  rep(i, n) if (a[i] == n - 1) pos = i;

  string ans = "";
  const auto Swap = [&]() {
    ans += 'S';
    swap(a[0], a[1]);
  };
  const auto Rotate = [&]() {
    ans += 'R';
    pos = (pos - 1 + n) % n;
    rotate(a.begin(), a.begin() + 1, a.end());
  };
  for (int x = n - 2; x >= 0; --x) {
    while (a[0] != x) Rotate();
    while (pos >= 2) Swap(), Rotate();
    assert(a[0] == x);
    assert(a[0] + 1 == a[1]);
    assert(pos == 1);
    pos--;
    Debug(x, a, pos, ans);
  }
  assert(is_sorted(a.begin(), a.end()));
  cout << ans << '\n';
  return 0;
}
0