結果
問題 |
No.3183 Swap or Rotate
|
ユーザー |
![]() |
提出日時 | 2025-06-20 21:32:33 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 3,723 bytes |
コンパイル時間 | 2,997 ms |
コンパイル使用メモリ | 281,972 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 21:32:38 |
合計ジャッジ時間 | 3,983 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> #include <cassert> using namespace std; using ll = long long int; using u64 = unsigned long long; using pll = pair<ll, ll>; // #include <atcoder/all> // using namespace atcoder; #define REP(i, a, b) for (ll i = (a); i < (b); i++) #define REPrev(i, a, b) for (ll i = (a); i >= (b); i--) #define ALL(coll) (coll).begin(), (coll).end() #define SIZE(v) ((ll)((v).size())) #define REPOUT(i, a, b, exp, sep) REP(i, (a), (b)) cout << (exp) << (i + 1 == (b) ? "" : (sep)); cout << "\n" // @@ !! LIM(forall f:intDiv) // ---- inserted library file forall.cc #define EX_REP_LL(i, from, to) for (ll i = (from); i < (to); i++) #define EX_REP_RB(x, coll) for (auto x : coll) #define EXGEN(rep_part, cond, yes, no_behaviour) ([&]() { rep_part if (cond) return (yes); no_behaviour; }()) #define EXISTS_BASE(rep_part, cond) EXGEN(rep_part, cond, true, return false) #define EXFIND_BASE(rep_part, cond, t) EXGEN(rep_part, cond, t, assert(0)) #define EXFIND_D_BASE(rep_part, cond, t, def) EXGEN(rep_part, cond, t, return def) #define EXISTS(i, from, to, cond) EXISTS_BASE(EX_REP_LL(i, from, to), cond) #define FORALL(i, from, to, cond) (not EXISTS(i, from, to, not (cond))) #define EXFIND(i, from, to, cond) EXFIND_BASE(EX_REP_LL(i, from, to), cond, i) #define EXFIND_D(i, from, to, cond, def) EXFIND_D_BASE(EX_REP_LL(i, from, to), cond, i, def) #define EXISTS_C(x, coll, cond) EXISTS_BASE(EX_REP_RB(x, coll), cond) #define FORALL_C(x, coll, cond) (not EXISTS_C(x, coll, not (cond))) #define EXFIND_C(x, coll, cond) EXFIND_BASE(EX_REP_RB(x, coll), cond, x) #define EXFIND_D_C(x, coll, cond, def) EXFIND_D_BASE(EX_REP_RB(x, coll), cond, x, def) #define COUNT_BASE(rep_part, cond) ([&](){ ll ret = 0; rep_part if (cond) ret++; return ret; }()) #define COUNT(i, from, to, cond) COUNT_BASE(EX_REP_LL(i, from, to), cond) #define COUNT_C(x, coll, cond) COUNT_BASE(EX_REP_RB(x, coll), cond) #define IMPLIES(a, b) (not (a) or (b)) // ---- end forall.cc // ---- inserted function f:intDiv from util.cc // imod, divFloor, divCeil // imod(x, y) : remainder of x for y // for y > 0: // imod(x, y) = r where x = dy + r, 0 <= r < y // imod(x, -y) = r where x = dy + r, 0 >= r > y // Thus, imod( 10, 7) = 3 // imod(-10, 7) = 4 // imod( 10, -7) = -4 // imod(-10, -7) = -3 ll imod(ll x, ll y) { ll v = x % y; if ((x >= 0) == (y >= 0)) return v; else return v == 0 ? 0 : v + y; } // Integer Division; regardless pos/neg ll divFloor(ll x, ll y) { if (x > 0) { if (y > 0) return x / y; else return (x - y - 1) / y; }else { if (y > 0) return (x - y + 1) / y; else return x / y; } } ll divCeil(ll x, ll y) { if (x > 0) { if (y > 0) return (x + y - 1) / y; else return x / y; }else { if (y > 0) return x / y; else return (x + y + 1) / y; } } // Just a note. For d \in Z and t \in R, // d < t <=> d < ceil(t), d <= t <=> d <= floor(t), // d > t <=> d > floor(t), d >= t <=> d >= ceil(t). // ---- end f:intDiv // @@ !! LIM -- end mark -- int main(/* int argc, char *argv[] */) { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(20); ll N; cin >> N; // @InpVec(N, P) [yIUCS9IE] auto P = vector(N, ll()); for (int i = 0; i < N; i++) { ll v; cin >> v; P[i] = v; } // @End [yIUCS9IE] string ans; REPrev(i, N - 2, 0) { ll j0 = EXFIND(j, 0, N, P[j] == i); REP(k, 0, j0) { ans += 'R'; P.push_back(P[0]); P.erase(P.begin()); } while (P[1] != i + 1) { ans += 'S'; swap(P[0], P[1]); ans += 'R'; P.push_back(P[0]); P.erase(P.begin()); } } cout << ans << endl; return 0; }