From 94cc807e9ae918d8375607d9c67821f2319326ee Mon Sep 17 00:00:00 2001 From: Sumonta Saha Mridul Date: Mon, 14 Aug 2023 20:43:49 +0600 Subject: [PATCH] Add : Codeforces Contest Solutions Added --- .../A - Spy Detected.cpp | 90 ++++++++ .../B - Almost Rectangle.cpp | 135 ++++++++++++ .../C - A-B Palindrome.cpp | 194 ++++++++++++++++++ .../A-Square String.cpp | 134 ++++++++++++ .../B - Squares and Cubes.cpp | 129 ++++++++++++ .../C - Wrong Addition.cpp | 159 ++++++++++++++ Codeforces Round 766 (Div. 2)/Not-Shading.cpp | 168 +++++++++++++++ Codeforces Round 766 (Div. 2)/Not-Sitting.cpp | 134 ++++++++++++ .../Berland-Music.cpp | 166 +++++++++++++++ .../Construct-A-Rectangle.cpp | 142 +++++++++++++ Good Bye 2021/Integer-Diversity.cpp | 116 +++++++++++ 11 files changed, 1567 insertions(+) create mode 100644 Codeforces Round 713 (Div. 3)/A - Spy Detected.cpp create mode 100644 Codeforces Round 713 (Div. 3)/B - Almost Rectangle.cpp create mode 100644 Codeforces Round 713 (Div. 3)/C - A-B Palindrome.cpp create mode 100644 Codeforces Round 762 (Div. 3)/A-Square String.cpp create mode 100644 Codeforces Round 762 (Div. 3)/B - Squares and Cubes.cpp create mode 100644 Codeforces Round 762 (Div. 3)/C - Wrong Addition.cpp create mode 100644 Codeforces Round 766 (Div. 2)/Not-Shading.cpp create mode 100644 Codeforces Round 766 (Div. 2)/Not-Sitting.cpp create mode 100644 Educational Codeforces Round 120 (Rated for Div. 2)/Berland-Music.cpp create mode 100644 Educational Codeforces Round 120 (Rated for Div. 2)/Construct-A-Rectangle.cpp create mode 100644 Good Bye 2021/Integer-Diversity.cpp diff --git a/Codeforces Round 713 (Div. 3)/A - Spy Detected.cpp b/Codeforces Round 713 (Div. 3)/A - Spy Detected.cpp new file mode 100644 index 0000000..5f5f85f --- /dev/null +++ b/Codeforces Round 713 (Div. 3)/A - Spy Detected.cpp @@ -0,0 +1,90 @@ +// ** Sumonta Saha Mridul ** SWE - SUST +/* + + * ###### ## ## ## ## ####### ## ## ######## ### + ! ## ## ## ## ### ### ## ## ### ## ## ## ## + ? ## ## ## #### #### ## ## #### ## ## ## ## + * ###### ## ## ## ### ## ## ## ## ## ## ## ## ## + ! ## ## ## ## ## ## ## ## #### ## ######### + ? ## ## ## ## ## ## ## ## ## ### ## ## ## + * ###### ####### ## ## ####### ## ## ## ## ## + +*/ +#include +using namespace std; + +#define ll long long +#define ull unsigned long long +#define pb push_back +#define pii pair +#define pll pair +#define mp(a, b) make_pair(a, b) +#define vi vector +#define vll vector +#define vii vector +#define Mi map +#define mii map +#define all(a) (a).begin(), (a).end() +#define f first +#define s second +#define lb lower_bound +#define ub upper_bound +#define sz(x) (int)x.size() +#define endl '\n' + +#define F(i, s, e) for (ll i = s; i < e; ++i) +#define rep(i, a, b) for (int i = a; i < b; i++) +#define rem(i, a, b) for (int i = a; i > b; i--) +#define P(str) cout << str << endl + +#define fast \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL) + +#define mod 1000000007 +#define INF numeric_limits::max(); +#define NINF numeric_limits::min(); +const int N = int(1e5 + 3); + +int main() +{ + fast; + int t; + cin >> t; + + while (t--) + { + int n; + cin >> n; + + int a, key1 = 1; + cin >> a; + + int a1 = 1, key2 = 0, a2 = 0; + + for (int i = 2; i <= n; i++) + { + + int x; + cin >> x; + + if (x == a) + { + key1 = i; + a1++; + } + + else + { + key2 = i; + a2++; + } + } + + if (a2 > a1) + cout << key1 << endl; + else + cout << key2 << endl; + } +} diff --git a/Codeforces Round 713 (Div. 3)/B - Almost Rectangle.cpp b/Codeforces Round 713 (Div. 3)/B - Almost Rectangle.cpp new file mode 100644 index 0000000..5638178 --- /dev/null +++ b/Codeforces Round 713 (Div. 3)/B - Almost Rectangle.cpp @@ -0,0 +1,135 @@ +// ** Sumonta Saha Mridul ** SWE - SUST +/* + + * ###### ## ## ## ## ####### ## ## ######## ### + ! ## ## ## ## ### ### ## ## ### ## ## ## ## + ? ## ## ## #### #### ## ## #### ## ## ## ## + * ###### ## ## ## ### ## ## ## ## ## ## ## ## ## + ! ## ## ## ## ## ## ## ## #### ## ######### + ? ## ## ## ## ## ## ## ## ## ### ## ## ## + * ###### ####### ## ## ####### ## ## ## ## ## + +*/ +#include +using namespace std; + +#define ll long long +#define ull unsigned long long +#define pb push_back +#define pii pair +#define pll pair +#define mp(a, b) make_pair(a, b) +#define vi vector +#define vll vector +#define vii vector +#define Mi map +#define mii map +#define all(a) (a).begin(), (a).end() +#define f first +#define s second +#define lb lower_bound +#define ub upper_bound +#define sz(x) (int)x.size() +#define endl '\n' + +#define F(i, s, e) for (ll i = s; i < e; ++i) +#define rep(i, a, b) for (int i = a; i < b; i++) +#define rem(i, a, b) for (int i = a; i > b; i--) +#define P(str) cout << str << endl + +#define fast \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL) + +#define mod 1000000007 +#define INF numeric_limits::max(); +#define NINF numeric_limits::min(); +const int N = int(1e5 + 3); + +int main() +{ + fast; + + int t; + cin >> t; + + while (t--) + { + int n; + cin >> n; + + int a = 0, b = 0, c = 0, d = 0; + int p = 0; + + char ans[n][n]; + + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + cin >> ans[i][j]; + + if (ans[i][j] == '*') + { + if (p == 0) + { + a = i; + b = j; + p = 1; + } + + else + { + c = i; + d = j; + } + } + } + } + + if (b == d) + { + if (b == 0) + { + ans[a][b+1] = '*'; + ans[c][d+1] = '*'; + } + else + { + ans[a][b-1] = '*'; + ans[c][d-1] = '*'; + } + } + + if(a == c) + { + if (a == 0) + { + ans[a+1][b] = '*'; + ans[c+1][d] = '*'; + } + else + { + ans[a-1][b] = '*'; + ans[c-1][d] = '*'; + } + + } + + else + { + ans[a][d] = '*'; + ans[c][b] = '*'; + } + + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + cout << ans[i][j]; + } + cout << endl; + } + } +} diff --git a/Codeforces Round 713 (Div. 3)/C - A-B Palindrome.cpp b/Codeforces Round 713 (Div. 3)/C - A-B Palindrome.cpp new file mode 100644 index 0000000..e0a9bf6 --- /dev/null +++ b/Codeforces Round 713 (Div. 3)/C - A-B Palindrome.cpp @@ -0,0 +1,194 @@ +// ** Sumonta Saha Mridul ** SWE - SUST +/* + + * ###### ## ## ## ## ####### ## ## ######## ### + ! ## ## ## ## ### ### ## ## ### ## ## ## ## + ? ## ## ## #### #### ## ## #### ## ## ## ## + * ###### ## ## ## ### ## ## ## ## ## ## ## ## ## + ! ## ## ## ## ## ## ## ## #### ## ######### + ? ## ## ## ## ## ## ## ## ## ### ## ## ## + * ###### ####### ## ## ####### ## ## ## ## ## + +*/ +#include +using namespace std; + +#define ll long long +#define ull unsigned long long +#define pb push_back +#define pii pair +#define pll pair +#define mp(a, b) make_pair(a, b) +#define vi vector +#define vll vector +#define vii vector +#define Mi map +#define mii map +#define all(a) (a).begin(), (a).end() +#define f first +#define s second +#define lb lower_bound +#define ub upper_bound +#define sz(x) (int)x.size() +#define endl '\n' + +#define F(i, s, e) for (ll i = s; i < e; ++i) +#define rep(i, a, b) for (int i = a; i < b; i++) +#define rem(i, a, b) for (int i = a; i > b; i--) +#define P(str) cout << str << endl + +#define fast \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL) + +#define mod 1000000007 +#define INF numeric_limits::max(); +#define NINF numeric_limits::min(); +const int N = int(1e5 + 3); + +void solve() +{ + int a, b; + cin >> a >> b; + + int c = 0; + + string s; + cin >> s; + + int n = s.size(); + + for (int i = 0; i < n; i++) + { + if (s[i] == '0') + a--; + if (s[i] == '1') + b--; + if (s[i] == '?') + c++; + } + + if (c == 0) + { + for (int i = 0; i < n / 2; i++) + { + if (s[i] != s[n - 1 - i]) + { + cout << -1 << "\n"; + return; + } + } + if (a > 0 || b > 0) + { + cout << -1 << "\n"; + return; + } + cout << s << "\n"; + return; + } + for (int i = 0; i < n / 2; i++) + { + if (s[i] == '?' && s[n - i - 1] != '?') + { + if (s[n - i - 1] == '0' && a > 0) + { + s[i] = '0'; + a--; + } + else if (s[n - i - 1] == '0' && a == 0) + { + cout << -1 << "\n"; + return; + } + else if (s[n - i - 1] == '1' && b > 0) + { + s[i] = '1'; + b--; + } + else + { + cout << -1 << "\n"; + return; + } + } + else if (s[n - i - 1] == '?' && s[i] != '?') + { + if (s[i] == '0' && a > 0) + { + s[n - i - 1] = '0'; + a--; + } + else if (s[i] == '0' && a == 0) + { + cout << -1 << "\n"; + return; + } + else if (s[i] == '1' && b > 0) + { + s[n - i - 1] = '1'; + b--; + } + else + { + cout << -1 << "\n"; + return; + } + } + } + for (int i = 0; i < n / 2; i++) + { + if (s[i] == '?' && s[n - i - 1] == '?') + { + if (a >= 2) + s[i] = '0', s[n - i - 1] = '0', a -= 2; + else if (b >= 2) + s[i] = '1', s[n - i - 1] = '1', b -= 2; + else + { + cout << -1 << "\n"; + return; + } + } + } + if (n % 2 == 1 && s[n / 2] == '?') + { + if (a > 0) + s[n / 2] = '0', a--; + else if (b > 0) + s[n / 2] = '1', b--; + else + { + cout << -1 << "\n"; + return; + } + } + if (a > 0 || b > 0) + { + cout << -1 << "\n"; + return; + } + for (int i = 0; i < n / 2; i++) + { + if (s[i] != s[n - 1 - i]) + { + cout << -1 << "\n"; + return; + } + } + cout << s << "\n"; + return; +} + +int main() +{ + fast; + + int t; + cin >> t; + + while (t--) + { + solve(); + } +} diff --git a/Codeforces Round 762 (Div. 3)/A-Square String.cpp b/Codeforces Round 762 (Div. 3)/A-Square String.cpp new file mode 100644 index 0000000..c24cf26 --- /dev/null +++ b/Codeforces Round 762 (Div. 3)/A-Square String.cpp @@ -0,0 +1,134 @@ +// ** Sumonta Saha Mridul ** SWE - SUST +/* + + * ###### ## ## ## ## ####### ## ## ######## ### + ! ## ## ## ## ### ### ## ## ### ## ## ## ## + ? ## ## ## #### #### ## ## #### ## ## ## ## + * ###### ## ## ## ### ## ## ## ## ## ## ## ## ## + ! ## ## ## ## ## ## ## ## #### ## ######### + ? ## ## ## ## ## ## ## ## ## ### ## ## ## + * ###### ####### ## ## ####### ## ## ## ## ## + +*/ +#include +using namespace std; + +#define ll long long +#define ull unsigned long long + +#define f first +#define se second +#define lb lower_bound +#define ub upper_bound +#define pb push_back + +#define pii pair +#define pll pair +#define mp(a, b) make_pair(a, b) +#define vi vector +#define vll vector +#define vii vector +#define sll set +#define qll queue +#define stll stack +#define Mi map +#define mii map +#define alls(a) (a).begin(), (a).end() +#define sz(x) (int)x.size() + +#define size(s) s.length() +#define all(v) (v.begin, v.end) +#define rev(v) reverse(v.begin, v.end) +#define srt(v) sort(v.begin, v.end) + +#define F(i, s, e) for (ll i = s; i < e; ++i) +#define rep(i, a, b) for (int i = a; i < b; i++) +#define rem(i, a, b) for (int i = a; i > b; i--) +#define pv(v) \ + for (ll i : v) \ + cout << i << " "; \ + cout << endl; + +#define max3(a, b, c) max(max((a), (b)), (c)) +#define min3(a, b, c) min(min((a), (b)), (c)) + +#define cin(n) cin >> n +#define cin2(a, b) cin >> a >> b; +#define cin3(a, b, c) cin >> a >> b >> c; +#define printE(str) cout << str << endl +#define print(str) cout << str << endl +#define endl '\n' +#define Y cout << "YES\n" +#define No cout << "NO\n" +#define ye cout << "Yes\n" +#define no cout << "No\n" + +#define sp " " +#define enter cout << endl; + +#define fast \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL) + +#define mod 1000000007 +#define inf 1000000000000000005 +#define INF numeric_limits::max(); +#define NINF numeric_limits::min(); +const int N = int(1e5 + 3); + +#define fo(i, a, b) for (int i = a; i <= b; i++) + +//* char a = 'A'; int num = (int) a; +//* char a = '2'; int num = a-48; + +ll mod_mul(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a * b) % mod) + mod) % mod; +} +ll mod_add(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a + b) % mod) + mod) % mod; +} + +int main() +{ + fast; + int t; + cin >> t; + + while (t--) + { + string s; + cin >> s; + + int size = s.length(); + + if (size % 2 != 0) + { + cout << "NO" << endl; + continue; + } + + bool check = true; + int end = size / 2; + + for (int i = 0; i < end; i++) + { + if (s[i] != s[end + i]) + { + check = false; + break; + } + } + + if (check) + cout << "YES" << endl; + else + cout << "NO" << endl; + } +} diff --git a/Codeforces Round 762 (Div. 3)/B - Squares and Cubes.cpp b/Codeforces Round 762 (Div. 3)/B - Squares and Cubes.cpp new file mode 100644 index 0000000..d21aaf5 --- /dev/null +++ b/Codeforces Round 762 (Div. 3)/B - Squares and Cubes.cpp @@ -0,0 +1,129 @@ +// ** Sumonta Saha Mridul ** SWE - SUST +/* + + * ###### ## ## ## ## ####### ## ## ######## ### + ! ## ## ## ## ### ### ## ## ### ## ## ## ## + ? ## ## ## #### #### ## ## #### ## ## ## ## + * ###### ## ## ## ### ## ## ## ## ## ## ## ## ## + ! ## ## ## ## ## ## ## ## #### ## ######### + ? ## ## ## ## ## ## ## ## ## ### ## ## ## + * ###### ####### ## ## ####### ## ## ## ## ## + +*/ +#include +using namespace std; + +#define ll long long +#define ull unsigned long long + +#define f first +#define se second +#define lb lower_bound +#define ub upper_bound +#define pb push_back + +#define pii pair +#define pll pair +#define mp(a, b) make_pair(a, b) +#define vi vector +#define vll vector +#define vii vector +#define sll set +#define qll queue +#define stll stack +#define Mi map +#define mii map +#define alls(a) (a).begin(), (a).end() +#define sz(x) (int)x.size() + + +#define all(v) (v.begin, v.end) +#define rev(v) reverse(v.begin, v.end) +#define srt(v) sort(v.begin, v.end) + +#define F(i, s, e) for (ll i = s; i < e; ++i) +#define rep(i, a, b) for (int i = a; i < b; i++) +#define rem(i, a, b) for (int i = a; i > b; i--) +#define pv(v) \ + for (ll i : v) \ + cout << i << " "; \ + cout << endl; + +#define max3(a, b, c) max(max((a), (b)), (c)) +#define min3(a, b, c) min(min((a), (b)), (c)) + +#define cin(n) cin >> n +#define cin2(a, b) cin >> a >> b; +#define cin3(a, b, c) cin >> a >> b >> c; +#define printE(str) cout << str << endl +#define print(str) cout << str << endl +#define endl '\n' +#define Y cout << "YES\n" +#define No cout << "NO\n" +#define ye cout << "Yes\n" +#define no cout << "No\n" + +#define sp " " +#define enter cout << endl; + +#define fast \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL) + +#define mod 1000000007 +#define inf 1000000000000000005 +#define INF numeric_limits::max(); +#define NINF numeric_limits::min(); +const int N = int(1e5 + 3); + +#define fo(i, a, b) for (int i = a; i <= b; i++) + +//* char a = 'A'; int num = (int) a; +//* char a = '2'; int num = a-48; + +ll mod_mul(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a * b) % mod) + mod) % mod; +} +ll mod_add(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a + b) % mod) + mod) % mod; +} + +int main() +{ + fast; + int t; + cin >> t; + + while (t--) + { + ll n; + cin >> n; + + ll count = 1; + + set arr; + + for (ll i = 1; i * i <= n; i++) + { + if (i * i <= n ) + { + arr.insert(i*i) ; + } + + if (i * i * i <= n ) + + { + arr.insert(i*i*i) ; + } + } + + cout << arr.size() << endl; + } +} diff --git a/Codeforces Round 762 (Div. 3)/C - Wrong Addition.cpp b/Codeforces Round 762 (Div. 3)/C - Wrong Addition.cpp new file mode 100644 index 0000000..cbaa7f9 --- /dev/null +++ b/Codeforces Round 762 (Div. 3)/C - Wrong Addition.cpp @@ -0,0 +1,159 @@ +// ** Sumonta Saha Mridul ** SWE - SUST +/* + + * ###### ## ## ## ## ####### ## ## ######## ### + ! ## ## ## ## ### ### ## ## ### ## ## ## ## + ? ## ## ## #### #### ## ## #### ## ## ## ## + * ###### ## ## ## ### ## ## ## ## ## ## ## ## ## + ! ## ## ## ## ## ## ## ## #### ## ######### + ? ## ## ## ## ## ## ## ## ## ### ## ## ## + * ###### ####### ## ## ####### ## ## ## ## ## + +*/ +#include +using namespace std; + +#define ll long long +#define ull unsigned long long + +#define f first +#define se second +#define lb lower_bound +#define ub upper_bound +#define pb push_back + +#define pii pair +#define pll pair +#define mp(a, b) make_pair(a, b) +#define vi vector +#define vll vector +#define vii vector +#define sll set +#define qll queue +#define stll stack +#define Mi map +#define mii map +#define alls(a) (a).begin(), (a).end() +#define sz(x) (int)x.size() + +#define all(v) (v.begin, v.end) +#define rev(v) reverse(v.begin, v.end) +#define srt(v) sort(v.begin, v.end) + +#define F(i, s, e) for (ll i = s; i < e; ++i) +#define rep(i, a, b) for (int i = a; i < b; i++) +#define rem(i, a, b) for (int i = a; i > b; i--) +#define pv(v) \ + for (ll i : v) \ + cout << i << " "; \ + cout << endl; + +#define max3(a, b, c) max(max((a), (b)), (c)) +#define min3(a, b, c) min(min((a), (b)), (c)) + +#define cin(n) cin >> n +#define cin2(a, b) cin >> a >> b; +#define cin3(a, b, c) cin >> a >> b >> c; +#define printE(str) cout << str << endl +#define print(str) cout << str << endl +#define endl '\n' +#define Y cout << "YES\n" +#define No cout << "NO\n" +#define ye cout << "Yes\n" +#define no cout << "No\n" + +#define sp " " +#define enter cout << endl; + +#define fast \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL) + +#define mod 1000000007 +#define inf 1000000000000000005 +#define INF numeric_limits::max(); +#define NINF numeric_limits::min(); +const int N = int(1e5 + 3); + +#define fo(i, a, b) for (int i = a; i <= b; i++) + +//* char a = 'A'; int num = (int) a; +//* char a = '2'; int num = a-48; + +ll mod_mul(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a * b) % mod) + mod) % mod; +} +ll mod_add(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a + b) % mod) + mod) % mod; +} + +int main() +{ + fast; + int t; + cin >> t; + + while (t--) + { + ll a, s; + cin >> a >> s; + + vll b; + bool notpossible = false; + + while (s) + { + ll x = a % 10; + ll y = s % 10; + + if (x <= y) + b.push_back(y - x); + + else + { + s /= 10; + + y += 10 * (s % 10); + + if (x < y && y >= 10 && y < 19) + b.push_back(y - x); + else + { + notpossible = true; + break; + } + } + + a /= 10; + s /= 10; + } + + if (notpossible || a) + { + cout << -1 << endl; + continue ; + } + + reverse(b.begin() , b.end()) ; + + bool check = false; + for (int f = 0; f < b.size(); f++) + { + if (b[f] == 0 && check == false) + continue; + else + { + cout << b[f]; + check = true; + } + } + cout << endl; + } +} diff --git a/Codeforces Round 766 (Div. 2)/Not-Shading.cpp b/Codeforces Round 766 (Div. 2)/Not-Shading.cpp new file mode 100644 index 0000000..8a33305 --- /dev/null +++ b/Codeforces Round 766 (Div. 2)/Not-Shading.cpp @@ -0,0 +1,168 @@ +// ** Sumonta Saha Mridul ** SWE - SUST +/* + + * ###### ## ## ## ## ####### ## ## ######## ### + ! ## ## ## ## ### ### ## ## ### ## ## ## ## + ? ## ## ## #### #### ## ## #### ## ## ## ## + * ###### ## ## ## ### ## ## ## ## ## ## ## ## ## + ! ## ## ## ## ## ## ## ## #### ## ######### + ? ## ## ## ## ## ## ## ## ## ### ## ## ## + * ###### ####### ## ## ####### ## ## ## ## ## + +*/ +#include +using namespace std; + +#define ll long long +#define ull unsigned long long + +#define f first +#define se second +#define lb lower_bound +#define ub upper_bound +#define pb push_back + +#define pii pair +#define pll pair +#define mp(a, b) make_pair(a, b) +#define vi vector +#define vll vector +#define vii vector +#define sll set +#define qll queue +#define stll stack +#define Mi map +#define mii map +#define alls(a) (a).begin(), (a).end() +#define sz(x) (int)x.size() + +#define Size(s) s.length() +#define all(v) (v.begin, v.end) +#define rev(v) reverse(v.begin, v.end) +#define srt(v) sort(v.begin, v.end) + +#define F(i, s, e) for (ll i = s; i < e; ++i) +#define rep(i, a, b) for (int i = a; i < b; i++) +#define rem(i, a, b) for (int i = a; i > b; i--) +#define pv(v) \ + for (ll i : v) \ + cout << i << " "; \ + cout << endl; + +#define max3(a, b, c) max(max((a), (b)), (c)) +#define min3(a, b, c) min(min((a), (b)), (c)) + +#define cin(n) cin >> n +#define cin2(a, b) cin >> a >> b; +#define cin3(a, b, c) cin >> a >> b >> c; +#define printE(str) cout << str << endl +#define print(str) cout << str << endl +#define endl '\n' +#define Y cout << "YES\n" +#define No cout << "NO\n" +#define ye cout << "Yes\n" +#define no cout << "No\n" + +#define sp " " +#define enter cout << endl; + +#define fast \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL) + +#define mod 1000000007 +#define inf 1000000000000000005 +#define INF numeric_limits::max(); +#define NINF numeric_limits::min(); +const int N = int(1e5 + 3); + +#define foi(i, a, b) for (int i = a; i < b; i++) +#define foI(i, a, b) for (int i = a; i <= b; i++) +#define fol(i, a, b) for (ll i = a; i < b; i++) +#define foL(i, a, b) for (ll i = a; i <= b; i++) + +//* char a = 'A'; int num = (int) a; +//* char a = '2'; int num = a-48; + +ll mod_mul(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a * b) % mod) + mod) % mod; +} +ll mod_add(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a + b) % mod) + mod) % mod; +} + +int main() +{ + fast; + int t; + cin >> t; + + while (t--) + { + int n, m; + cin >> n >> m; + + char arr[n][m]; + + int r, c; + cin >> r >> c; + + ll count = 0; + + for (int i = 0; i < n; i++) + { + for (int j = 0; j < m; j++) + { + cin >> arr[i][j]; + + if (arr[i][j] == 'W') + count++; + } + } + + if (count == n * m) + { + cout << -1 << endl; + continue; + } + + if(arr[r-1][c-1] == 'B') + { + cout << 0 < +using namespace std; + +#define ll long long +#define ull unsigned long long + +#define f first +#define se second +#define lb lower_bound +#define ub upper_bound +#define pb push_back + +#define pii pair +#define pll pair +#define mp(a, b) make_pair(a, b) +#define vi vector +#define vll vector +#define vii vector +#define sll set +#define qll queue +#define stll stack +#define Mi map +#define mii map +#define alls(a) (a).begin(), (a).end() +#define sz(x) (int)x.size() + +#define Size(s) s.length() +#define all(v) (v.begin, v.end) +#define rev(v) reverse(v.begin, v.end) +#define srt(v) sort(v.begin, v.end) + +#define F(i, s, e) for (ll i = s; i < e; ++i) +#define rep(i, a, b) for (int i = a; i < b; i++) +#define rem(i, a, b) for (int i = a; i > b; i--) +#define pv(v) \ + for (ll i : v) \ + cout << i << " "; \ + cout << endl; + +#define max3(a, b, c) max(max((a), (b)), (c)) +#define min3(a, b, c) min(min((a), (b)), (c)) + +#define cin(n) cin >> n +#define cin2(a, b) cin >> a >> b; +#define cin3(a, b, c) cin >> a >> b >> c; +#define printE(str) cout << str << endl +#define print(str) cout << str << endl +#define endl '\n' +#define Y cout << "YES\n" +#define No cout << "NO\n" +#define ye cout << "Yes\n" +#define no cout << "No\n" + +#define sp " " +#define enter cout << endl; + +#define fast \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL) + +#define mod 1000000007 +#define inf 1000000000000000005 +#define INF numeric_limits::max(); +#define NINF numeric_limits::min(); +const int N = int(1e5 + 3); + +#define foi(i, a, b) for (int i = a; i < b; i++) +#define foI(i, a, b) for (int i = a; i <= b; i++) +#define fol(i, a, b) for (ll i = a; i < b; i++) +#define foL(i, a, b) for (ll i = a; i <= b; i++) + +//* char a = 'A'; int num = (int) a; +//* char a = '2'; int num = a-48; + +ll mod_mul(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a * b) % mod) + mod) % mod; +} +ll mod_add(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a + b) % mod) + mod) % mod; +} + +int main() +{ + fast; + int t; + cin >> t; + + while (t--) + { + int n, m; + cin >> n >> m; + + vector arr; + + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= m; j++) + { + int a = abs(1 - i) + abs(m - j); + int b = abs(1 - i) + abs(1 - j); + int c = abs(n - i) + abs(1 - j); + int d = abs(n - i) + abs(m - j); + + int ans = max(max(a, b), max(c, d)); + arr.push_back(ans); + } + } + + sort(arr.begin(), arr.end()); + + for (auto it : arr) + cout << it << sp; + cout << endl; + } +} diff --git a/Educational Codeforces Round 120 (Rated for Div. 2)/Berland-Music.cpp b/Educational Codeforces Round 120 (Rated for Div. 2)/Berland-Music.cpp new file mode 100644 index 0000000..aee809a --- /dev/null +++ b/Educational Codeforces Round 120 (Rated for Div. 2)/Berland-Music.cpp @@ -0,0 +1,166 @@ +// ** Sumonta Saha Mridul ** SWE - SUST +/* + + * ###### ## ## ## ## ####### ## ## ######## ### + ! ## ## ## ## ### ### ## ## ### ## ## ## ## + ? ## ## ## #### #### ## ## #### ## ## ## ## + * ###### ## ## ## ### ## ## ## ## ## ## ## ## ## + ! ## ## ## ## ## ## ## ## #### ## ######### + ? ## ## ## ## ## ## ## ## ## ### ## ## ## + * ###### ####### ## ## ####### ## ## ## ## ## + +*/ +#include +using namespace std; + +#define ll long long +#define ull unsigned long long + +#define f first +#define se second +#define lb lower_bound +#define ub upper_bound +#define pb push_back + +#define pii pair +#define pll pair +#define mp(a, b) make_pair(a, b) +#define vi vector +#define vll vector +#define vii vector +#define sll set +#define qll queue +#define stll stack +#define Mi map +#define mii map +#define alls(a) (a).begin(), (a).end() +#define sz(x) (int)x.size() + +#define Size(s) s.length() +#define all(v) (v.begin, v.end) +#define rev(v) reverse(v.begin, v.end) +#define srt(v) sort(v.begin, v.end) + +#define F(i, s, e) for (ll i = s; i < e; ++i) +#define rep(i, a, b) for (int i = a; i < b; i++) +#define rem(i, a, b) for (int i = a; i > b; i--) +#define pv(v) \ + for (ll i : v) \ + cout << i << " "; \ + cout << endl; + +#define max3(a, b, c) max(max((a), (b)), (c)) +#define min3(a, b, c) min(min((a), (b)), (c)) + +#define cin(n) cin >> n +#define cin2(a, b) cin >> a >> b; +#define cin3(a, b, c) cin >> a >> b >> c; +#define printE(str) cout << str << endl +#define print(str) cout << str << endl +#define endl '\n' +#define Y cout << "YES\n" +#define No cout << "NO\n" +#define ye cout << "Yes\n" +#define no cout << "No\n" + +#define sp " " +#define enter cout << endl; + +#define fast \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL) + +#define mod 1000000007 +#define inf 1000000000000000005 +#define INF numeric_limits::max(); +#define NINF numeric_limits::min(); +const int N = int(1e5 + 3); + +#define fo(i, a, b) for (int i = a; i <= b; i++) + +//* char a = 'A'; int num = (int) a; +//* char a = '2'; int num = a-48; + +ll mod_mul(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a * b) % mod) + mod) % mod; +} +ll mod_add(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a + b) % mod) + mod) % mod; +} + +bool cmp(pair &a, pair &b) +{ + return a.second < b.second; +} + +int main() +{ + fast; + int t; + cin >> t; + + while (t--) + { + ll n; + cin >> n; + + vll arr(n); + vll rank(n); + + for (int i = 0; i < n; i++) + { + cin >> arr[i]; + } + + string s; + cin >> s; + + vector> trackliked; + vector> trackdisliked; + + for (int i = 0; i < s.length(); i++) + { + char c = s[i]; + if (c == '1') + { + trackliked.push_back(make_pair(i, arr[i])); + } + + else + { + trackdisliked.push_back(make_pair(i, arr[i])); + } + } + + sort(trackliked.begin(), trackliked.end(), cmp); + sort(trackdisliked.begin(), trackdisliked.end(), cmp); + + int k = 1; + for (auto it : trackdisliked) + { + // cout << it.second << " "<< it.first< +using namespace std; + +#define ll long long +#define ull unsigned long long + +#define f first +#define se second +#define lb lower_bound +#define ub upper_bound +#define pb push_back + +#define pii pair +#define pll pair +#define mp(a, b) make_pair(a, b) +#define vi vector +#define vll vector +#define vii vector +#define sll set +#define qll queue +#define stll stack +#define Mi map +#define mii map +#define alls(a) (a).begin(), (a).end() +#define sz(x) (int)x.size() + +#define Size(s) s.length() +#define all(v) (v.begin, v.end) +#define rev(v) reverse(v.begin, v.end) +#define srt(v) sort(v.begin, v.end) + +#define F(i, s, e) for (ll i = s; i < e; ++i) +#define rep(i, a, b) for (int i = a; i < b; i++) +#define rem(i, a, b) for (int i = a; i > b; i--) +#define pv(v) \ + for (ll i : v) \ + cout << i << " "; \ + cout << endl; + +#define max3(a, b, c) max(max((a), (b)), (c)) +#define min3(a, b, c) min(min((a), (b)), (c)) + +#define cin(n) cin >> n +#define cin2(a, b) cin >> a >> b; +#define cin3(a, b, c) cin >> a >> b >> c; +#define printE(str) cout << str << endl +#define print(str) cout << str << endl +#define endl '\n' +#define Y cout << "YES\n" +#define No cout << "NO\n" +#define ye cout << "Yes\n" +#define no cout << "No\n" + +#define sp " " +#define enter cout << endl; + +#define fast \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL) + +#define mod 1000000007 +#define inf 1000000000000000005 +#define INF numeric_limits::max(); +#define NINF numeric_limits::min(); +const int N = int(1e5 + 3); + +#define fo(i, a, b) for (int i = a; i <= b; i++) + +//* char a = 'A'; int num = (int) a; +//* char a = '2'; int num = a-48; + +ll mod_mul(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a * b) % mod) + mod) % mod; +} +ll mod_add(ll a, ll b) +{ + a = a % mod; + b = b % mod; + return (((a + b) % mod) + mod) % mod; +} + +int main() +{ + fast; + + int t; + cin >> t; + + while (t--) + { + vll arr(3); + int odd = 0, even = 0; + + for (int i = 0; i < 3; i++) + { + cin >> arr[i]; + if (arr[i] % 2 == 0) + even++; + else + odd++; + } + + sort(arr.begin(), arr.end()); + + if (odd == 3) + cout << "NO" << endl; + + else if (even == 3 || even == 1) + { + if (arr[0] + arr[1] == arr[2]) + cout << "YES" << endl; + + else if (arr[0] == arr[1] && arr[2] == arr[1]) + cout << "YES" << endl; + + else if (arr[0] == arr[1] || arr[2] == arr[1]) + cout << "YES" << endl; + + else + cout << "NO" << endl; + } + + else + cout << "NO" << endl; + } +} diff --git a/Good Bye 2021/Integer-Diversity.cpp b/Good Bye 2021/Integer-Diversity.cpp new file mode 100644 index 0000000..399d7ad --- /dev/null +++ b/Good Bye 2021/Integer-Diversity.cpp @@ -0,0 +1,116 @@ +// ** Sumonta Saha Mridul ** SWE - SUST +/* + + * ###### ## ## ## ## ####### ## ## ######## ### + ! ## ## ## ## ### ### ## ## ### ## ## ## ## + ? ## ## ## #### #### ## ## #### ## ## ## ## + * ###### ## ## ## ### ## ## ## ## ## ## ## ## ## + ! ## ## ## ## ## ## ## ## #### ## ######### + ? ## ## ## ## ## ## ## ## ## ### ## ## ## + * ###### ####### ## ## ####### ## ## ## ## ## + +*/ +#include +using namespace std; + +#define ll long long +#define ull unsigned long long + +#define f first +#define se second +#define lb lower_bound +#define ub upper_bound +#define pb push_back + +#define pii pair +#define pll pair +#define mp(a, b) make_pair(a, b) +#define vi vector +#define vll vector +#define vii vector +#define sll set +#define qll queue +#define stll stack +#define Mi map +#define mii map +#define alls(a) (a).begin(), (a).end() +#define sz(x) (int)x.size() + +#define Size(s) s.length() +#define all(v) (v.begin, v.end) +#define rev(v) reverse(v.begin, v.end) +#define srt(v) sort(v.begin, v.end) + +#define F(i, s, e) for (ll i = s; i < e; ++i) +#define rep(i, a, b) for (int i = a; i < b; i++) +#define rem(i, a, b) for (int i = a; i > b; i--) +#define pv(v) \ + for (ll i : v) \ + cout << i << " "; \ + cout << endl; + +#define max3(a,b,c) max(max((a),(b)),(c)) +#define min3(a,b,c) min(min((a),(b)),(c)) + +#define cin(n) cin >> n +#define cin2(a, b) cin >> a >> b; +#define cin3(a, b, c) cin >> a >> b >> c; +#define printE(str) cout << str << endl +#define print(str) cout << str << endl +#define endl '\n' +#define Y cout << "YES\n" +#define No cout << "NO\n" +#define ye cout << "Yes\n" +#define no cout << "No\n" + +#define sp " " +#define enter cout << endl; + +#define fast \ + ios_base::sync_with_stdio(false); \ + cin.tie(NULL); \ + cout.tie(NULL) + +#define mod 1000000007 +#define inf 1000000000000000005 +#define INF numeric_limits::max(); +#define NINF numeric_limits::min(); +const int N = int(1e5 + 3); + +#define foi(i, a, b) for (int i = a; i < b; i++) +#define foI(i, a, b) for (int i = a; i <= b; i++) +#define fol(i, a, b) for (ll i = a; i < b; i++) +#define foL(i, a, b) for (ll i = a; i <= b; i++) + +//* char a = 'A'; int num = (int) a; +//* char a = '2'; int num = a-48; + +ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;} +ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;} + +int main() +{ + fast; + int t; + cin >> t; + + while(t--) + { + int n ; + cin >> n ; + + int arr[n] ; + setp ; + + for(int i = 0 ; i < n ; i++) + { + cin >> arr[i] ; + if(p.find((-1)*arr[i]) ==p.end()) p.insert((-1)*arr[i]) ; + else p.insert(arr[i]); + + } + + cout << p.size() <