Problem:
Problem D:
Deadly Dice Game
T.I. Financial Group, a world-famous group of finance companies, has decided to hold an evil gambling
game in which insolvent debtors compete for special treatment of exemption from their debts.
In this game, each debtor starts from one cell on the stage called the Deadly Ring. The Deadly Ring
consists of N cells and each cell is colored black or red. Each cell is connected to exactly two other
adjacent cells and all the cells form a ring. At the start of the game, each debtor chooses which cell to
start. Then he rolls a die and moves on the ring in clockwise order by cells as many as the number of
spots shown on the upside of the die. This step is called a round, and each debtor repeats a round
T
times.
A debtor will be exempted from his debt if he is standing on a red cell after he finishes all the rounds.
On the other hand, if he finishes the game at a black cell, he will be sent somewhere else and forced to
devote his entire life to hard labor.
You have happened to take part in this game. As you are allowed to choose the starting cell, you want to
start from a cell that maximizes the probability of finishing the game at a red cell. Fortunately you can
bring a laptop PC to the game stage, so you have decided to write a program that calculates the maximum
winning probability.
Input
The input consists of multiple datasets.
Each dataset consists of two lines. The first line contains two integers
N
(1 ≤
N
≤ 2000) and
T
(1 ≤
T
≤ 2000) in this order, delimited with a single space. The second line contains a string of
N
characters that
consists of characters ‘
R
’ and ‘
B
’, which indicate red and black respectively. This string represents the
colors of the cells in clockwise order.
The input is terminated by a line with two zeros. This is not part of any datasets and should not be
processed.
Output
For each dataset, print the maximum probability of finishing the game at a red cell in one line. Your
program may output an arbitrary number of digits after the decimal point, provided that the absolute
error does not exceed 10
-8
.
Sample Input
6 1
RBRBRB
10 1
RBBBRBBBBB
10 2
RBBBRBBBBB
10 10
RBBBBBBBBB
0 0
Output for the Sample Input
0.50000000
0.33333333
0.22222222
0.10025221

Submitted solutions:

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define Endl endl
#define all(a) a.begin(), a.end()
#define pr(i, j) make_pair(i, j)
#define isin(x, l, r) (l <= x && x < r)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define srt(ar) sort(ar.begin(), ar.end())
#define rev(ar) reverse(ar.begin(), ar.end())
#define jge(f, s, t) cout << (f ? s : t) << endl
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define printar(ar)             \
    do                          \
    {                           \
        for (auto dbg : ar)     \
        {                       \
            cout << dbg << " "; \
        }                       \
        cout << endl;           \
    } while (0)
const ll inf = 1e18;
const ld pi = 3.14159265358979;
const ld eps = 1e-9;
template <class T, ll n, ll idx = 0>
auto make_vec(const ll (&d)[n], const T &init) noexcept
{
    if constexpr (idx < n)
        return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else
        return init;
}

template <class T, ll n>
auto make_vec(const ll (&d)[n]) noexcept
{
    return make_vec(d, T{});
}
//////////////// 以下を貼る ////////////////
template <class T>
size_t HashCombine(const size_t seed, const T &v)
{
    return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
/* pair用 */
template <class T, class S>
struct std::hash<std::pair<T, S>>
{
    size_t operator()(const std::pair<T, S> &keyval) const noexcept
    {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};
////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while (true)
    {
        ll n, t;
        cin >> n >> t;
        if (n == 0)
        {
            break;
        }
        string s;
        cin >> s;
        vector<vector<ld>> dp(t + 1, vector<ld>(n, 0));
        dp[0][0] = 1;
        rep(i, 0, t)
        {
            rep(j, 0, n)
            {
                rep(k, 1, 7)
                {
                    dp[i + 1][(j + k) % n] += dp[i][j] / 6.0;
                }
            }
        }
        vector<ld> ar = dp[t];
        ld ans = 0;
        rep(i, 0, n)
        {
            ld sub = 0;
            rep(j, 0, n)
            {
                if (s[(i + j) % n] == 'R')
                {
                    sub += ar[j];
                }
            }
            chmax(ans, sub);
        }
        cout << setprecision(15) << fixed << ans << Endl;
    }
}
accuracy: 1
time_ms: 1880
memory_kb: 66320
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
double dp[2000];
double nex[2000];
int main() {
  int n,t;
  while(cin>>n>>t,n||t) {
    for(int i=0;i<=n;i+=1)dp[i]=0;
    for(int i=0;i<n;i+=1){
        char x;
        cin>>x;
        dp[i]=(x=='R');
    }
    for(int i=0;i<t;i+=1){
      memset(nex,0,sizeof(nex));
      for(int j=0;j<n;j+=1)
         for(int k=1;k<=6;k+=1)
           nex[(j+k)%n]+=dp[j]/6;
      for(int j=0;j<n;j+=1)dp[j]=nex[j];
    }
    cout<<fixed<<setprecision(8)<<*max_element(dp,dp+n)<<endl;
  }
}
accuracy: 1
time_ms: 1370
memory_kb: 3232
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
double dp[2000];
double nex[2000];
int main() {
  int n,t;
  while(cin>>n>>t,n||t) {
    for(int i=0;i<=n;i+=1)dp[i]=0;
    for(int i=0;i<n;i+=1){
        char x;
        cin>>x;
        dp[i]=(x=='R');
    }
    for(int i=0;i<t;i+=1){
      memset(nex,0,sizeof(nex));
      for(int j=0;j<n;j+=1)
         for(int k=0;k<6;k+=1)
           nex[(j+k+1)%n]+=dp[j]/6;
      for(int j=0;j<n;j+=1)dp[j]=nex[j];
    }
    cout<<fixed<<setprecision(8)<<*max_element(dp,dp+n)<<endl;
  }
}
accuracy: 1
time_ms: 1370
memory_kb: 3312
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
double dp[2000];
double nex[2000];
int main() {
  int n,t;
  while(cin>>n>>t,n||t) {
    for(int i=0;i<=n;i+=1)dp[i]=0;
    for(int i=0;i<n;i+=1){
        char x;
        cin>>x;
        dp[i]=(x=='R');
    }
    for(int i=0;i<t;i+=1){
      memset(nex,0,sizeof(nex));
      for(int j=0;j<n;j+=1)
         for(int k=0;k<6;k+=1)
           nex[(j+k+1)%n]+=dp[j]/6;
      for(int j=0;j<n;j+=1)dp[j]=nex[j];
    }
    cout<<fixed<<setprecision(9)<<*max_element(dp,dp+n)<<endl;
  }
}
accuracy: 1
time_ms: 1370
memory_kb: 3220
final_rank: 5

code_snippet: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

char c[2000];
double dp[2000];
double nex[2000];

int main() {
  int n,t;
  while(cin>>n>>t,n||t) {
    for(int i=0;i<=n;i+=1)dp[i]=0;
    for(int i=0;i<n;i+=1){
        cin>>c[i];
        if (c[i]=='R') dp[i] = 1;
    }
    for(int i=0;i<t;i+=1){
      memset(nex,0,sizeof(nex));
      for(int j=0;j<n;j+=1)
         for(int k=0;k<6;k+=1)
           nex[(j+k+1)%n]+=dp[j]/6;
      for(int j=0;j<n;j+=1)dp[j]=nex[j];
    }
    cout<<fixed<<setprecision(9);
    cout<<*max_element(dp,dp+n)<<endl;
  }
}
accuracy: 1
time_ms: 1370
memory_kb: 3308
final_rank: 7

code_snippet: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

char c[2000];
double dp[2000];
double nex[2000];

int main() {
  int n,t;
  while(cin>>n>>t,n||t) {
    for(int i=0;i<=n;i+=1)dp[i]=0;
    for(int i=0;i<n;i+=1){
        cin>>c[i];
        if (c[i]=='R') dp[i] = 1;
    }
    for(int i=0;i<t;i+=1){
      memset(nex,0,sizeof(nex));
      for(int j=0;j<n;j+=1)
         for(int k=0;k<6;k+=1)
        nex[(j+k+1)%n]+=dp[j]/6;
      for(int j=0;j<n;j+=1)dp[j]=nex[j];
    }
    printf("%.10f\n", *max_element(dp,dp+n));
  }
}
accuracy: 1
time_ms: 1370
memory_kb: 3052
final_rank: 3

code_snippet: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

char c[2000];
double dp[2000];
double nex[2000];

int main() {
  int n,t;
  while(cin>>n>>t,n||t) {
    for(int i=0;i<=n;i+=1)dp[i]=0;
    for(int i=0;i<n;i+=1){
        cin>>c[i];
        if (c[i]=='R') dp[i] = 1;
    }
    for(int i=0;i<t;i+=1){
      memset(nex,0,sizeof(nex));
      for(int j=0;j<n;j+=1)
         for(int k=0;k<6;k+=1)
        nex[(j+k+1)%n] += dp[j]/6;
      memcpy(dp,nex,sizeof(nex));
    }
    printf("%.10f\n", *max_element(dp,dp+n));
  }
}
accuracy: 1
time_ms: 1360
memory_kb: 3312
final_rank: 4

code_snippet: #include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <functional>
#include <algorithm>
#include <random>
#include <cmath>
#include <climits>
#include <iomanip>
#include <cfloat>
#include <set>
#include <map>
#include <tuple>
#include <array>
int main() {
	std::array<std::array<double, 2000>, 2> memo;
	int n, t;
	std::string str;
	double max = 0;
	std::cout << std::setprecision(16);
	while (true) {
		std::cin >> n >> t;
		if (n == 0 && t == 0) return 0;
		std::cin >> str;
		for (auto i = 0; i < str.size(); ++i) {
			if (str[i] == 'R') memo[0][i] = 1;
			else memo[0][i] = 0;
		}
		for (auto times = 0; times < t; ++times) {
			for (auto i = 0; i < n; ++i) {
				memo[(times + 1) % 2][i] = 0;
				for (auto d = 1; d <= 6; ++d) {
					memo[(times + 1) % 2][i] += memo[times % 2][(i + d) % n];
				}
				memo[(times + 1) % 2][i] /= 6;
			}
		}
		max = 0;
		for (auto i = 0; i < n; ++i) {
			if (max < memo[t % 2][i]) max = memo[t % 2][i];
		}
		std::cout << max << std::endl;
	}
}
accuracy: 1
time_ms: 1320
memory_kb: 3252
final_rank: 2

code_snippet: #include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld=long double;

int main() {
	while(true){
		int N,M;cin>>N>>M;
		if(!N)break;
		vector<vector<ld>>dps(M + 1, vector<ld>(N));
		dps[0][0]=1;
		for (int i = 0; i < M; ++i) {
			for (int j = 0; j < N; ++j) {
				for (int k = 1; k <= 6; ++k) {
					dps[i+1][(j+k)%N]+=dps[i][j]/6;
				}
			}
		}
		string st;cin>>st;
		ld ans=0;
		for (int i = 0; i < N; ++i) {
			ld  nans=0;
			for (int j = 0; j < N; ++j) {
				if (st[j]=='R') {
					nans+=dps[M][(i+j)%N];
				}
			}
			ans=max(ans,nans);
		}
		
		cout<<setprecision(10)<<fixed<<ans<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 3880
memory_kb: 65504
final_rank: 20

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N,T;
double dp[2001][2001]; //dp[??´???][?????°] = ?¢????
char buf[2001];

void func(){

	scanf("%s",buf);
	for(int i = 0; i < N; i++){
		if(buf[i] == 'R'){
			dp[i][0] = 1.0;
		}else{
			dp[i][0] = 0.0;
		}
	}

	for(int count = 1; count <= T; count++){
		for(int loc = 0; loc < N; loc++){
			dp[loc][count] = 0;
			for(int i = 1; i <= 6; i++){
				dp[loc][count] += (dp[(loc+i)%N][count-1])/6.0;
			}
		}
	}

	double ans = 0.0;
	for(int loc = 0; loc < N; loc++){
		ans = max(ans,dp[loc][T]);
	}

	printf("%.10lf\n",ans);

}

int main(){

	while(true){
		scanf("%d %d",&N,&T);
		if(N == 0 && T == 0)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 2810
memory_kb: 34452
final_rank: 12

code_snippet: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int n,T;string S;double dp[2001][2001];
int main(){
	while(true){
		cin>>n>>T;if(n==0 && T==0)break;
		for(int i=0;i<=T;i++){for(int j=0;j<n;j++)dp[i][j]=0;}
		dp[0][0]=1.0;
		for(int i=0;i<T;i++){
			for(int j=0;j<n;j++){
				int c=j;
				for(int k=0;k<6;k++){
					c++;if(c==n)c=0;
					dp[i+1][c]+=dp[i][j]/6.0;
				}
			}
		}
		cin>>S;double maxn=0;
		for(int i=0;i<n;i++){
			double cnt=0;int c=i;
			for(int j=0;j<n;j++){
				if(S[c]=='R')cnt+=dp[T][j];
				c++;if(c==n)c=0;
			}
			maxn=max(maxn,cnt);
		}
		printf("%.15lf\n",maxn);
	}
	return 0;
}
accuracy: 1
time_ms: 2150
memory_kb: 34360
final_rank: 9

code_snippet: #include <string>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m; double pre[2009], dp[2009]; string s;
int main() {
	while (cin >> n >> m, n) {
		cin >> s;
		fill(pre, pre + n, 0.0); pre[0] = 1.0;
		for (int i = 0; i < m; i++) {
			fill(dp, dp + n, 0.0);
			for (int j = 0; j < n; j++) {
				int c = j;
				for (int k = 1; k <= 6; k++) {
					if (++c == n) c = 0;
					dp[c] += pre[j];
				}
			}
			for (int j = 0; j < n; j++) pre[j] = dp[j] / 6.0;
		}
		double ret = 0.0;
		for (int i = 0; i < n; i++) {
			double res = 0.0;
			int c = i;
			for (int j = 0; j < n; j++) {
				if (s[j] == 'R') res += pre[c];
				if (++c == n) c = 0;
			}
			ret = max(ret, res);
		}
		cout << fixed << setprecision(15) << ret << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 970
memory_kb: 3188
final_rank: 1

code_snippet: #include <bits/stdc++.h>

using namespace std;

int main()
{
    int N, T;
    while (cin >> N >> T, N) {
        string s;
        cin >> s;

        vector<vector<double>> dp(T + 1, vector<double>(N));
        for (int i = 0; i < N; i++) {
            dp[0][i] = (s[i] == 'R');
        }        
        for (int i = 0; i < T; i++) {
            for (int j = 0; j < N; j++) {
                if (dp[i][j] == 0) continue;
                for (int k = 1; k <= 6; k++) {
                    int nj = (j + k) % N;
                    dp[i + 1][nj] += dp[i][j] / 6;
                }
            }
        }
        printf("%.10f\n", *max_element(dp[T].begin(), dp[T].end()));
    }    
    return 0;
}
accuracy: 1
time_ms: 2710
memory_kb: 34316
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
double dp[2001][2000];
int main() {
  int n,m,i,j,k;
  while(cin>>n>>m&&n){
    string s;
    cin>>s;
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(i=0;i<m;i++)for(j=0;j<n;j++)for(k=1;k<=6;k++)dp[i+1][(j+k)%n]+=dp[i][j]/6;
    double ans=0;
    for(j=0;j<n;j++){
      double sum=0;
      for(i=0;i<n;i++)sum+=dp[m][i]*(s[(j+i)%n]=='R');
      ans=max(ans,sum);
    }
    printf("%.10f\n",ans);
  }
  return 0;
}
accuracy: 1
time_ms: 3550
memory_kb: 34492
final_rank: 16

code_snippet: #include <bits/stdc++.h>

using namespace std;

double dp[2002][2002];

int main()
{
  int N, T;
  while(cin >> N >> T, N || T) {
    string ring; cin >> ring;

    reverse(ring.begin(), ring.end());

    memset(dp, 0.0, sizeof(dp));
    for(int i = 0; i < N; i++) {
      if(ring[i] == 'R') dp[0][i] = 1.0;
    }

    for(int i = 0; i < T; i++) {
      for(int j = 0; j < N; j++) {
	for(int k = 1; k <= 6; k++) {
	  dp[i+1][(j+k)%N] += dp[i][j] / 6;
	}
      }
    }

    double ans = 0.0;
    for(int i = 0; i < N; i++) ans = max(ans, dp[T][i]);

    printf("%.10f\n", ans);
  }
  return 0;
}
accuracy: 1
time_ms: 2920
memory_kb: 34424
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string mp;
int n,T;
double mem[2001][2001];
bool used[2001][2001];

double dfs(int t,int pos){
  if(t==T)return mem[t][pos]=(mp[pos]=='R');
  if(used[t][pos])return mem[t][pos];
  used[t][pos]=1;

  double res=0;
  for(int i=1;i<=6;i++)res+=dfs(t+1,(pos+i)%n);
  return mem[t][pos]=res/6;
}

int main(){
  while(1){
    cin>>n>>T;
    if(!n&&!T)break;
    cin>>mp;

    memset(used,0,sizeof(used));  
    for(int i=0;i<2001;i++)
      for(int j=0;j<2001;j++) mem[i][j]=0;
    
    
    double ans=0;  
    for(int i=0;i<n;i++) ans=max(ans,dfs(0,i));
    printf("%.10f\n",ans);
  }
  return 0;
}
accuracy: 1
time_ms: 4130
memory_kb: 38588
final_rank: 18

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

double dp[2001][2000];
int main() {
  int n,m;
  while(cin >> n >> m && n) {
    string s;
    cin >> s;
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=0;i<m;i++)
      for(int j=0;j<n;j++)
        for(int k=1;k<=6;k++)dp[i+1][(j+k)%n]+=dp[i][j]/6;
    double ans=0;
    for(int j=0;j<n;j++) {
      rotate(s.begin(),s.begin()+1,s.end());
      double sum=0;
      for(int i=0;i<n;i++) {
        if(s[i]=='R') sum+=dp[m][i];
      }
      ans=max(ans,sum);
    }
    printf("%.10f\n",ans);
  }
  return 0;
}
accuracy: 1
time_ms: 3060
memory_kb: 34356
final_rank: 15

code_snippet: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 2000;

/* typedef */

/* global variables */

int n, t;
string rng;
double dp[2][MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n >> t;
    if (n == 0) break;

    cin >> rng;

    double max_p = 0;
    
    int cur = 0, nxt = 1;
    for (int i = 0; i < n; i++) dp[0][i] = (rng[i] == 'R') ? 1 : 0;

    for (int ti = 0; ti < t; ti++) {
      for (int i = 0; i < n; i++) dp[nxt][i] = 0;

      for (int i = 0; i < n; i++) {
	for (int d = 1; d <= 6; d++) {
	  dp[nxt][i] += dp[cur][(i + d) % n] / 6;
	}
      }

      cur ^= 1;
      nxt ^= 1;
    }

    for (int i = 0; i < n; i++)
      if (max_p < dp[cur][i]) max_p = dp[cur][i];

    printf("%.8lf\n", max_p);
  }

  return 0;
}
accuracy: 1
time_ms: 4660
memory_kb: 1280
final_rank: 10

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
char str[2100];
double dp[2100][2100];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		scanf("%s",str);
		for(int i=0;i<=b;i++)for(int j=0;j<a;j++)dp[i][j]=0;
		dp[0][0]=1;
		for(int i=0;i<b;i++){
			for(int j=0;j<a;j++){
				for(int k=1;k<=6;k++){
					dp[i+1][(j+k)%a]+=dp[i][j]/6;
				}
			}
		}
		double ret=0;
		for(int i=0;i<a;i++){
			double val=0;
			for(int j=0;j<a;j++){
				if(str[(i+j)%a]=='R')val+=dp[b][j];
			}
			ret=max(ret,val);
		}
		printf("%.12f\n",ret);
	}
}
accuracy: 1
time_ms: 5020
memory_kb: 33904
final_rank: 19

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
 
using namespace std;
 
const int N = 2000;
 
double dp[2][N];
int n, t;
 
void init(){
  fill(dp[0], dp[2], 0.0);
  dp[0][0] = 1.0;
  for(int i=0;i<t;i++){
    int cur = i % 2;
    int nxt = (i + 1) % 2;
    for(int j=0;j<n;j++) dp[nxt][j] = 0.0;
    for(int j=0;j<n;j++){
      for(int k=0;k<6;k++){
    dp[nxt][(j+k)%n] += dp[cur][j] / 6.0;
      }
    }
  }
}
 
int main(){
  while(cin >> n >> t && (n|t)){
    init();
    string s;
    cin >> s;
    double ans = 0.0;
    for(int i=0;i<n;i++){
      double sum = 0.0;
      for(int j=0;j<n;j++){
    int p = (i + j) % n;
    if(s[p] == 'R'){
      sum += dp[t%2][j];
    }
      }
      ans = max(ans, sum);
    }
    printf("%.10f\n", ans);
  }
  return 0;
}
accuracy: 1
time_ms: 5110
memory_kb: 1284
final_rank: 14