結果

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#include<atcoder/all>
using namespace atcoder;
using mint=atcoder::modint1000000007;

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define rng(i,l,r) for(int i=(l);i<(r);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrng(i,l,r) for(int i=(r)-1;i>=(l);i--)

#define fi first
#define se second
#define all(x) (x).begin(),(x).end()

struct fast_io{fast_io(){std::cin.tie(nullptr)->sync_with_stdio(false);}}_;

signed main(){
	int N;cin>>N;

	string ans="";
	vector<int> P(N);for(auto&&e:P)cin>>e;
	int c=0;

	while(1){
		if(P[c%N]==0)break;
		c++;
		ans+='R';
	}

	int t=c;

	while(1){
		// cout<<"P : ";
		// rep(i,N)cout<<P[(i+c)%N]<<" ";cout<<endl;
		bool flg=1;
		rep(i,N){
			if(P[(i+c)%N]!=i){
				flg=0;
				break;
			}
		}
		if(flg)break;

		if(c%N!=t){
			if(P[c%N]>P[(c+1)%N]){
				swap(P[c%N],P[(c+1)%N]);
				ans+='S';
			}
		}

		c++;
		ans+='R';
	}

	cout<<ans<<endl;
}
0