Skip to content

Commit c20dfd1

Browse files
committed
.
1 parent 2ac7ec3 commit c20dfd1

8 files changed

+303
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"A. Average Height","group":"Codeforces - Codeforces Round #715 (Div. 2)","url":"https://codeforces.com/contest/1509/problem/0","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1618583776201,"input":"4\n3\n1 1 2\n3\n1 1 1\n8\n10 9 13 15 3 16 9 13\n2\n18 9","output":"1 1 2\n1 1 1\n13 9 13 15 3 9 16 10\n9 18"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AAverageHeight"}},"batch":{"id":"70e37f86-671e-465c-a4cf-cd7bd55baf04","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeForces\\715 Div 2\\A_Average_Height.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"B. TMT Document","group":"Codeforces - Codeforces Round #715 (Div. 2)","url":"https://codeforces.com/contest/1509/problem/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1618586217833,"input":"5\n3\nTMT\n3\nMTT\n6\nTMTMTT\n6\nTMTTTT\n6\nTTMMTT","output":"YES\nNO\nYES\nNO\nYES"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BTMTDocument"}},"batch":{"id":"ee7804d3-fba1-4f36-91ed-58030632eb7f","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeForces\\715 Div 2\\B_TMT_Document.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"C. The Sports Festival","group":"Codeforces - Codeforces Round #715 (Div. 2)","url":"https://codeforces.com/contest/1509/problem/C","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"3\n3 1 2\n","output":"3\n","id":1618584754151},{"input":"1\n5\n","output":"0\n","id":1618584754181},{"input":"6\n1 6 3 3 6 3\n","output":"11\n","id":1618584754100},{"input":"6\n104 943872923 6589 889921234 1000000000 69\n","output":"2833800505\n","id":1618584754169}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CTheSportsFestival"}},"batch":{"id":"9a157f44-4e0b-45ec-99bd-5964b1b95068","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeForces\\715 Div 2\\C_The_Sports_Festival.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"D. Binary Literature","group":"Codeforces - Codeforces Round #715 (Div. 2)","url":"https://codeforces.com/contest/1509/problem/D","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"input":"2\n1\n00\n11\n01\n3\n011001\n111010\n010001\n","output":"010\n011001010\n","id":1618589377273},{"id":1618590926425,"input":"1\n2\n0000\n1111\n1011","output":""}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"DBinaryLiterature"}},"batch":{"id":"dcee641b-a5db-4867-8144-4193cd925b4a","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\CodeForces\\715 Div 2\\D_Binary_Literature.cpp"}
66 KB
Binary file not shown.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
2+
//------------------------------------------------------------------------------
3+
#include <iostream>
4+
#include <vector>
5+
// #include <bits/stdc++.h>
6+
// #include <cmath>
7+
// #include <algorithm>
8+
// #include <unordered_map>
9+
// #include <map>
10+
// #include <set>
11+
// #include <unordered_set>
12+
//------------------------------------------------------------------------------
13+
using namespace std;
14+
//------------------------------------------------------------------------------
15+
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
16+
#define v(Type) vector<Type>
17+
#define w(T) \
18+
int T; \
19+
cin >> T; \
20+
while (T--)
21+
#define int long long int
22+
#define mod 1000000007ll
23+
#define endl "\n"
24+
//------------------------------------------------------------------------------
25+
// Any fucntion can be called using Math.function_name();
26+
//------------------------------------------------------------------------------
27+
class Math
28+
{
29+
public:
30+
//Returns gcd of two numbers
31+
int gcd(int a, int b)
32+
{
33+
return (a % b == 0) ? b : gcd(b, a % b);
34+
}
35+
36+
//Returns lcm of two numbers
37+
int lcm(int a, int b)
38+
{
39+
return a * (b / gcd(a, b));
40+
}
41+
42+
// Returns flag array isPrime
43+
// isPrime[i] = true (if i is Prime)
44+
// isPrime[i] = false (if i is not Prime)
45+
vector<bool> *seiveOfEratosthenes(const int N)
46+
{
47+
vector<bool> *isPrime = new vector<bool>(N + 1, true);
48+
(*isPrime)[0] = (*isPrime)[1] = false;
49+
for (int i = 2; i * i <= N; ++i)
50+
if ((*isPrime)[i])
51+
for (int j = i * i; j <= N; j += i)
52+
(*isPrime)[j] = false;
53+
54+
return isPrime;
55+
}
56+
57+
//Returns (x ^ n)
58+
int pow(const int &x, int n)
59+
{
60+
if (n == 0)
61+
return 1;
62+
int h = pow(x, n / 2);
63+
return (n & 1) ? h * h * x : h * h;
64+
}
65+
66+
//Returns (x ^ n) % M
67+
int pow(const int &x, int n, const int &M)
68+
{
69+
if (n == 0)
70+
return 1;
71+
int h = pow(x, n / 2) % M;
72+
return (n & 1) ? (h * h * x) % M : (h * h) % M;
73+
}
74+
75+
//Returns all Primes <= N
76+
vector<int> *primesUptoN(const int N)
77+
{
78+
vector<bool> *isPrime = seiveOfEratosthenes(N);
79+
vector<int> *Primes = new vector<int>;
80+
if (2 <= N)
81+
(*Primes).push_back(2);
82+
for (int i = 3; i <= N; i += 2)
83+
if ((*isPrime)[i])
84+
(*Primes).push_back(i);
85+
return Primes;
86+
}
87+
88+
} Math;
89+
//------------------------------------------------------------------------------
90+
void solve()
91+
{
92+
int n;
93+
cin >> n;
94+
v(int) odd, even;
95+
96+
for (int i = 0; i < n; i++)
97+
{
98+
int temp;
99+
cin >> temp;
100+
101+
if (temp & 1)
102+
odd.push_back(temp);
103+
else
104+
even.push_back(temp);
105+
}
106+
107+
for (int &x : odd)
108+
cout << x << " ";
109+
110+
for (int &x : even)
111+
cout << x << " ";
112+
113+
cout << endl;
114+
}
115+
//------------------------------------------------------------------------------
116+
int32_t main()
117+
{
118+
FastIO;
119+
120+
w(T)
121+
solve();
122+
123+
return 0;
124+
}
125+
//------------------------------------------------------------------------------
59.5 KB
Binary file not shown.
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
2+
//------------------------------------------------------------------------------
3+
#include <iostream>
4+
#include <vector>
5+
// #include <bits/stdc++.h>
6+
// #include <cmath>
7+
// #include <algorithm>
8+
// #include <unordered_map>
9+
// #include <map>
10+
// #include <set>
11+
// #include <unordered_set>
12+
//------------------------------------------------------------------------------
13+
using namespace std;
14+
//------------------------------------------------------------------------------
15+
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
16+
#define v(Type) vector<Type>
17+
#define w(T) \
18+
int T; \
19+
cin >> T; \
20+
while (T--)
21+
#define int long long int
22+
#define mod 1000000007ll
23+
#define endl "\n"
24+
//------------------------------------------------------------------------------
25+
// Any fucntion can be called using Math.function_name();
26+
//------------------------------------------------------------------------------
27+
class Math
28+
{
29+
public:
30+
//Returns gcd of two numbers
31+
int gcd(int a, int b)
32+
{
33+
return (a % b == 0) ? b : gcd(b, a % b);
34+
}
35+
36+
//Returns lcm of two numbers
37+
int lcm(int a, int b)
38+
{
39+
return a * (b / gcd(a, b));
40+
}
41+
42+
// Returns flag array isPrime
43+
// isPrime[i] = true (if i is Prime)
44+
// isPrime[i] = false (if i is not Prime)
45+
vector<bool> *seiveOfEratosthenes(const int N)
46+
{
47+
vector<bool> *isPrime = new vector<bool>(N + 1, true);
48+
(*isPrime)[0] = (*isPrime)[1] = false;
49+
for (int i = 2; i * i <= N; ++i)
50+
if ((*isPrime)[i])
51+
for (int j = i * i; j <= N; j += i)
52+
(*isPrime)[j] = false;
53+
54+
return isPrime;
55+
}
56+
57+
//Returns (x ^ n)
58+
int pow(const int &x, int n)
59+
{
60+
if (n == 0)
61+
return 1;
62+
int h = pow(x, n / 2);
63+
return (n & 1) ? h * h * x : h * h;
64+
}
65+
66+
//Returns (x ^ n) % M
67+
int pow(const int &x, int n, const int &M)
68+
{
69+
if (n == 0)
70+
return 1;
71+
int h = pow(x, n / 2) % M;
72+
return (n & 1) ? (h * h * x) % M : (h * h) % M;
73+
}
74+
75+
//Returns all Primes <= N
76+
vector<int> *primesUptoN(const int N)
77+
{
78+
vector<bool> *isPrime = seiveOfEratosthenes(N);
79+
vector<int> *Primes = new vector<int>;
80+
if (2 <= N)
81+
(*Primes).push_back(2);
82+
for (int i = 3; i <= N; i += 2)
83+
if ((*isPrime)[i])
84+
(*Primes).push_back(i);
85+
return Primes;
86+
}
87+
88+
} Math;
89+
//------------------------------------------------------------------------------
90+
bool check(string &s)
91+
{
92+
int tc = 0;
93+
int mc = 0;
94+
for (int i = 0; i < s.length(); i++)
95+
if (s[i] == 'T')
96+
tc++;
97+
else
98+
mc++;
99+
return tc == 2 * mc;
100+
}
101+
102+
void solve()
103+
{
104+
int n;
105+
cin >> n;
106+
string s;
107+
cin >> s;
108+
bool ans = check(s);
109+
if (ans)
110+
111+
{
112+
v(int) tl(n, 0), tr(n, 0), ml(n, 0), mr(n, 0);
113+
tl[0] = (s[0] == 'T');
114+
ml[0] = (s[0] == 'M');
115+
116+
for (int i = 1; i < n; i++)
117+
{
118+
if (s[i] == 'T')
119+
tl[i]++;
120+
else
121+
ml[i]++;
122+
tl[i] += tl[i - 1];
123+
ml[i] += ml[i - 1];
124+
}
125+
126+
tr[n - 1] = (s[n - 1] == 'T');
127+
mr[n - 1] = (s[n - 1] == 'M');
128+
129+
for (int i = n - 2; i >= 0; i--)
130+
{
131+
if (s[i] == 'T')
132+
tr[i]++;
133+
else
134+
mr[i]++;
135+
tr[i] += tr[i + 1];
136+
mr[i] += mr[i + 1];
137+
}
138+
for (int i = 0; i < n; i++)
139+
{
140+
if (s[i] == 'M')
141+
{
142+
int l = tl[i] - (ml[i] - 1);
143+
int r = tr[i] - (mr[i] - 1);
144+
145+
if (l >= 1 and r >= 1)
146+
continue;
147+
else
148+
{
149+
// cout << l << " " << r << endl;
150+
ans = false;
151+
152+
break;
153+
}
154+
}
155+
}
156+
}
157+
if (ans)
158+
cout << "YES";
159+
else
160+
cout << "NO";
161+
162+
cout << endl;
163+
}
164+
//------------------------------------------------------------------------------
165+
int32_t main()
166+
{
167+
FastIO;
168+
169+
w(T)
170+
solve();
171+
172+
return 0;
173+
}
174+
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)