結果
| 問題 |
No.3183 Swap or Rotate
|
| コンテスト | |
| ユーザー |
nonon
|
| 提出日時 | 2025-08-07 20:34:55 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 1,000 ms |
| コード長 | 1,029 bytes |
| コンパイル時間 | 3,203 ms |
| コンパイル使用メモリ | 279,840 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-08-07 20:35:00 |
| 合計ジャッジ時間 | 5,122 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; }
bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> P(N);
for (auto &e : P) cin >> e;
string ans;
auto SWAP = [&] () -> void {
ans.push_back('S');
swap(P[0], P[1]);
};
auto ROTATE = [&] () -> void {
ans.push_back('R');
vector<int> Q(N);
for (int i = 0; i < N; i++) {
Q[i] = P[(i + 1) % N];
}
P = Q;
};
while (P[N - 1] != N - 1) ROTATE();
for (int i = N - 2; i >= 0; i--) {
if (P[i] == i) continue;
while (P[0] != i) ROTATE();
while (P[1] != i + 1) {
SWAP();
ROTATE();
}
while (P[i] != i) ROTATE();
}
// for (int i = 0; i < N; i++) cout << P[i] << " \n"[i + 1 == N];
cout << ans << endl;
}
nonon