From 70c8441a837563a8ca3b506f768b94b5d3bec7db Mon Sep 17 00:00:00 2001 From: ShazidMahsrafi Date: Thu, 1 Aug 2024 04:42:14 +0600 Subject: [PATCH] feat: Add solutions for Codeforces problems 1997 A, B, C, and D --- Codes/1997 A - Strong Password/1997A.cpp | 53 +++++++++++++++ Codes/1997 B - Make Three Regions/1997B.cpp | 65 +++++++++++++++++++ Codes/1997 C - Even Positions/1997C.cpp | 72 +++++++++++++++++++++ Codes/1997 D - Maximize the Root/1997D.cpp | 61 +++++++++++++++++ Readme.md | 4 ++ 5 files changed, 255 insertions(+) create mode 100644 Codes/1997 A - Strong Password/1997A.cpp create mode 100644 Codes/1997 B - Make Three Regions/1997B.cpp create mode 100644 Codes/1997 C - Even Positions/1997C.cpp create mode 100644 Codes/1997 D - Maximize the Root/1997D.cpp diff --git a/Codes/1997 A - Strong Password/1997A.cpp b/Codes/1997 A - Strong Password/1997A.cpp new file mode 100644 index 0000000..22bcba2 --- /dev/null +++ b/Codes/1997 A - Strong Password/1997A.cpp @@ -0,0 +1,53 @@ +#include +using namespace std; +#ifdef ONLINE_JUDGE +#define dbg(...) +#else +#include "Assets/debug.h" +#endif +#define int long long +#define ll long long +#define endl '\n' +#define ff first +#define ss second +#define ins insert +#define pb push_back +#define ppb pop_back +#define sz(x) (int)(x).size() +#define all(x) x.begin(), x.end() +#define rep(i,a,b) for(int i=a; i=b; --i) +#define yn(f) f? cout<<"YES\n":cout<<"NO\n" +#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr)); +ll pow(ll x,ll y,ll m=1e9+7) {ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;} + +void solve() +{ + string s; + cin>>s; + for(int i=1; i> TCS; + for (int TC = 1; TC <= TCS; ++TC) + { + // cout<<"Case "< +using namespace std; +#ifdef ONLINE_JUDGE +#define dbg(...) +#else +#include "Assets/debug.h" +#endif +#define int long long +#define ll long long +#define endl '\n' +#define ff first +#define ss second +#define ins insert +#define pb push_back +#define ppb pop_back +#define sz(x) (int)(x).size() +#define all(x) x.begin(), x.end() +#define rep(i,a,b) for(int i=a; i=b; --i) +#define yn(f) f? cout<<"YES\n":cout<<"NO\n" +#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr)); +ll pow(ll x,ll y,ll m=1e9+7) {ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;} + +void solve() +{ + int n; + cin>>n; + vectorv(2); + for(auto &i:v) cin>>i; + dbg(n,v); + int ans=0; + rep(i,0,2) + { + rep(j,0,n) + { + int ct=0; + if(j+1=0 && v[i][j-1]=='.') ct++; + dbg(ct); + if(ct<2) continue; + if(i==0) + { + if(v[i+1][j]=='.' && v[i+1][j-1]=='x' && v[i+1][j+1]=='x') ans++; + } + else + { + if(v[i-1][j]=='.' && v[i-1][j-1]=='x' && v[i-1][j+1]=='x') ans++; + } + } + } + cout<> TCS; + for (int TC = 1; TC <= TCS; ++TC) + { + // cout<<"Case "< +using namespace std; +#ifdef ONLINE_JUDGE +#define dbg(...) +#else +#include "Assets/debug.h" +#endif +#define int long long +#define ll long long +#define endl '\n' +#define ff first +#define ss second +#define ins insert +#define pb push_back +#define ppb pop_back +#define sz(x) (int)(x).size() +#define all(x) x.begin(), x.end() +#define rep(i,a,b) for(int i=a; i=b; --i) +#define yn(f) f? cout<<"YES\n":cout<<"NO\n" +#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr)); +ll pow(ll x,ll y,ll m=1e9+7) {ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;} + +void solve() +{ + int n; + string s; + cin>>n>>s; + int ct=0,cost=0; + vectorv; + for(int i=0; i> TCS; + for (int TC = 1; TC <= TCS; ++TC) + { + // cout<<"Case "< +using namespace std; +#ifdef ONLINE_JUDGE +#define dbg(...) +#else +#include "Assets/debug.h" +#endif +#define int long long +#define ll long long +#define endl '\n' +#define ff first +#define ss second +#define ins insert +#define pb push_back +#define ppb pop_back +#define sz(x) (int)(x).size() +#define all(x) x.begin(), x.end() +#define rep(i,a,b) for(int i=a; i=b; --i) +#define yn(f) f? cout<<"YES\n":cout<<"NO\n" +#define FAST (ios_base::sync_with_stdio(false), cin.tie(nullptr)); +ll pow(ll x,ll y,ll m=1e9+7) {ll ans=1;x%=m;while(y){if(y&1)ans=(ans*x)%m;x=(x*x)%m;y>>=1;}return ans;} + +void solve() +{ + int n; + cin>>n; + vectoradj[n], v(n); + for(auto &i:v) cin>>i; + rep(i,1,n) + { + int p; + cin>>p; + p--; + adj[p].pb(i); + } + function dfs = [&](int node)->int + { + int mn = INT_MAX; + for(auto child:adj[node]) + mn = min(mn, dfs(child)); + dbg(mn); + if(node == 0) return mn+v[0]; + if(mn == INT_MAX) return v[node]; + if(v[node] >= mn) return mn; + return (mn+v[node])/2; + }; + cout<> TCS; + for (int TC = 1; TC <= TCS; ++TC) + { + // cout<<"Case "<