-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Hall_of_Fame.cpp
107 lines (101 loc) · 1.91 KB
/
A_Hall_of_Fame.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define el endl
#define vi vector<int>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define ht unordered_map
#define uset unordered_set
#define int long long int
#define lld long double
#define INF INT_MAX
template <typename T>
istream &operator>>(istream &in, vector<T> &v)
{
for (auto &x : v)
in >> x;
return in;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v)
{
for (auto &x : v)
out << x << ' ';
return out;
}
double PI = acos(-1);
int mulmod(int a, int b, int mod)
{
int res = 0; // Initialize result
a = a % mod;
while (b > 0)
{
if (b % 2 == 1)
res = (res + a) % mod;
a = (a * 2) % mod;
b /= 2;
}
return res % mod;
}
void solve();
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--)
{
solve();
}
#ifndef ONLINE_JUDGE
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
#endif
}
void solve()
{
int n;
cin >> n;
string s;
cin >> s;
int flagL = 0;
int flagR = 0;
int indexR = -1;
int indexL = -1;
for (int i = 0; i < n; i++)
{
if (s[i] == 'L')
{
flagL = 1;
indexL = i;
}
if (s[i] == 'R')
{
flagR = 1;
indexR = i;
}
}
if (flagL == 0 || flagR == 0)
{
cout << -1 << el;
return;
}
// cout << flagR << el;
int count = 0;
for (int i = 0; i < n - 1; i++)
{
if (s[i] == 'R' && s[i + 1] == 'L')
{
cout << 0 << el;
return;
}
if (s[i] == 'L' && s[i + 1] == 'R')
{
cout << i + 1 << el;
return;
}
}
}