結果
| 問題 |
No.3183 Swap or Rotate
|
| コンテスト | |
| ユーザー |
zawakasu
|
| 提出日時 | 2025-06-20 21:35:19 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 1,000 ms |
| コード長 | 1,775 bytes |
| コンパイル時間 | 1,459 ms |
| コンパイル使用メモリ | 122,888 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 21:35:22 |
| 合計ジャッジ時間 | 2,709 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>
#include <ranges>
namespace ranges = std::ranges;
namespace views = std::views;
// #include "Src/Number/IntegerDivision.hpp"
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// #include "Src/Algebra/Group/AdditiveGroup.hpp"
// #include "Src/DataStructure/FenwickTree/FenwickTree.hpp"
// #include "Src/DataStructure/SegmentTree/SegmentTree.hpp"
// #include "Src/DataStructure/DisjointSetUnion/DisjointSetUnion.hpp"
// using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
int N, P[100];
void rotate(int f) {
assert(0 <= f and f < N);
std::vector<int> p(N);
for (int i = 0 ; i < N ; i++) p[i] = P[(i + f) % N];
for (int i = 0 ; i < N ; i++) P[i] = p[i];
}
int main() {
std::cin.tie(nullptr);
std::cout.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cin >> N;
for (int i = 0 ; i < N ; i++) std::cin >> P[i];
std::string ans;
while (true) {
int f = -1;
for (int i = 0 ; f == -1 and i < N ; i++) {
if (P[i] > P[(i + 1) % N] and P[(i + 1) % N] != 0) f = i;
}
if (f == -1) break;
rotate(f);
ans += std::string(f, 'R');
assert(P[0] > P[1] and P[1] != 0);
ans += 'S';
std::swap(P[0], P[1]);
}
int f = ranges::find(P, P + N, 0) - P;
rotate(f);
ans += std::string(f, 'R');
std::cout << ans << '\n';
// for (int i = 0 ; i < N ; i++) std::cerr << P[i] << ' ';
// std::cerr << std::endl;
for (int i = 0 ; i < N ; i++) assert(P[i] == i);
}
zawakasu