-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1509B TMT Document.cpp
53 lines (50 loc) · 918 Bytes
/
1509B TMT Document.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
/*
author : MishkatIT
created : Thursday 2023-04-20-12.55.51
*/
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
bool solve(void)
{
int n;
cin >> n;
string str;
cin >> str;
int t1, m, t2, i;
t1 = m = t2 = 0;
int mx = (n / 3);
if(mx * 3 != n)
return false;
for (i = 0; i < n; i++)
{
if(str[i] == 'T')
{
if(t1 < mx)
t1++;
else if(t2 < m)
t2++;
}
else if(m < t1)
m++;
else
return false;
}
if(t1 == mx && m == mx && t2 == mx && i == n)
return true;
return false;
}
int main()
{
fio;
int t;
cin >> t;
while(t--)
{
if(solve())
cout << "YES" << '\n';
else
cout << "NO" << '\n';
}
return 0;
}