-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
98 lines (83 loc) · 1.65 KB
/
B.cpp
File metadata and controls
98 lines (83 loc) · 1.65 KB
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
#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
int main()
{
fast
int t;
cin >> t;
while(t --)
{
int n;
cin >> n;
string s;
cin >> s;
int val = 0;
int m = 0, t = 0;
for(auto &e : s)
{
if(e == 'M')
{
m ++;
}
else
{
t ++;
}
}
if(s.at(0) != 'T' || s.at(n - 1) != 'T')
{
cout << "NO" << endl;
continue;
}
if(t != 2 * m)
{
cout << "NO" << endl;
continue;
}
int br = 0;
for(auto &e: s)
{
if(e == 'T')
{
val ++;
}
else
{
val --;
}
if(val < 0)
{
br = 1;
cout << "NO" << endl;
break;
}
if(val > m)
{
br = 1;
cout << "NO" << endl;
break;
}
}
if(!br)
{
if(val == m)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
}
}