結果
問題 |
No.3183 Swap or Rotate
|
ユーザー |
|
提出日時 | 2025-06-20 21:30:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 1,041 bytes |
コンパイル時間 | 1,768 ms |
コンパイル使用メモリ | 198,672 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 21:30:47 |
合計ジャッジ時間 | 2,845 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; template<class T> istream& operator >> (istream& is, vector<T>& vec) { for(T& x : vec) is >> x; return is; } template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for(auto &&v : a) cin >> v; auto check = [&](){ for(int i = 0; i < n; i++){ if((a[i] + 1) % n != a[(i + 1) % n]) return true; } return false; }; string ans; while(check()){ if(a[0] > a[1] && !(a[0] == n - 1 && a[1] == 0)){ ans += 'S'; swap(a[0], a[1]); } rotate(a.begin(), a.begin() + 1, a.end()); ans += 'R'; } while(a[0] != 0){ ans += 'R'; rotate(a.begin(), a.begin() + 1, a.end()); } cout << ans << '\n'; }