Add solutions for Codeforces problems 1985A, 1985B, 1985C, 1985D, and 1985E

This commit is contained in:
ShazidMahsrafi 2024-06-12 21:59:10 +06:00
parent 56a6f25363
commit 9c455619ee
6 changed files with 216 additions and 0 deletions

View File

@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
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 a,b;
cin>>a>>b;
swap(a[0],b[0]);
cout<<a<<" "<<b<<endl;
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int TCS = 1;
cin >> TCS;
for (int TC = 1; TC <= TCS; ++TC)
{
// cout<<"Case "<<TC<<": ";
solve();
}
}

View File

@ -0,0 +1,38 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
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;
int mx=0,x=-1;
for(int i=2; i<=n; ++i)
{
int sum=0;
for(int j=1; j*i<=n; ++j)
{
sum+=j*i;
}
if(sum>mx)
{
mx=sum;
x=i;
}
}
cout<<x<<endl;
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int TCS = 1;
cin >> TCS;
for (int TC = 1; TC <= TCS; ++TC)
{
// cout<<"Case "<<TC<<": ";
solve();
}
}

View File

@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
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()
{
ll n;
cin>>n;
ll mx=0, ct=0, sum=0;
for(ll i=0; i<n; ++i)
{
ll x;
cin>>x;
sum+=x;
mx=max(x,mx);
if(sum-mx==mx) ct++;
}
cout<<ct<<endl;
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int TCS = 1;
cin >> TCS;
for (int TC = 1; TC <= TCS; ++TC)
{
// cout<<"Case "<<TC<<": ";
solve();
}
}

View File

@ -0,0 +1,60 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
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,m;
cin>>n>>m;
vector<string>v;
for(int i=0; i<n; ++i)
{
string s;
cin>>s;
v.push_back(s);
}
int x=0,y=0, mx=0, my=0;
for(int i=0; i<n; ++i)
{
int ct=0;
for(int j=0; j<m; ++j)
{
if(v[i][j]=='#')
ct++;
}
if(ct>mx)
{
mx=ct;
x=i+1;
}
}
for(int j=0; j<m; ++j)
{
int ct=0;
for(int i=0; i<n; ++i)
{
if(v[i][j]=='#')
ct++;
}
if(ct>my)
{
my=ct;
y=j+1;
}
}
cout<<x<<" "<<y<<endl;
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int TCS = 1;
cin >> TCS;
for (int TC = 1; TC <= TCS; ++TC)
{
// cout<<"Case "<<TC<<": ";
solve();
}
}

View File

@ -0,0 +1,55 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
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;}
vector<ll> nums(ll n)
{
vector<ll> v;
for (ll i = 2; i * i <= n; ++i)
{
while (n % i == 0)
{
v.push_back(i);
n /= i;
}
}
if (n != 1)
v.push_back(n);
return v;
}
void solve()
{
ll x, y, z, k;
cin >> x >> y >> z >> k;
ll mx=0;
for(ll a=1; a<=x; ++a)
{
for(ll b=1; b<=y; ++b)
{
if(k%(a*b)) continue;
ll c=k/(a*b);
if(c<=z && a*b*c==k)
{
ll ct=(x-a+1)*(y-b+1)*(z-c+1);
mx=max(ct,mx);
}
}
}
cout<<mx<<endl;
}
signed main()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int TCS = 1;
cin >> TCS;
for (int TC = 1; TC <= TCS; ++TC)
{
// cout<<"Case "<<TC<<": ";
solve();
}
}

View File

@ -339,6 +339,11 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
| 327 | 1981 A | Turtle and Piggy Are Playing a Game | [Question](https://codeforces.com/problemset/problem/1981/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1981%20A%20-%20Turtle%20and%20Piggy%20Are%20Playing%20a%20Game) | 327 | 1981 A | Turtle and Piggy Are Playing a Game | [Question](https://codeforces.com/problemset/problem/1981/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1981%20A%20-%20Turtle%20and%20Piggy%20Are%20Playing%20a%20Game)
| 328 | 1981 B | Turtle and an Infinite Sequence | [Question](https://codeforces.com/problemset/problem/1981/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1981%20B%20-%20Turtle%20and%20an%20Infinite%20Sequence) | 328 | 1981 B | Turtle and an Infinite Sequence | [Question](https://codeforces.com/problemset/problem/1981/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1981%20B%20-%20Turtle%20and%20an%20Infinite%20Sequence)
| 329 | 1981 C | Turtle and an Incomplete Sequence | [Question](https://codeforces.com/problemset/problem/1981/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1981%20C%20-%20Turtle%20and%20an%20Incomplete%20Sequence) | 329 | 1981 C | Turtle and an Incomplete Sequence | [Question](https://codeforces.com/problemset/problem/1981/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1981%20C%20-%20Turtle%20and%20an%20Incomplete%20Sequence)
| 330 | 1985 A | Creating Words | [Question](https://codeforces.com/problemset/problem/1985/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20A%20-%20Creating%20Words)
| 331 | 1985 B | Maximum Multiple Sum | [Question](https://codeforces.com/problemset/problem/1985/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20B%20-%20Maximum%20Multiple%20Sum)
| 332 | 1985 C | Good Prefixes | [Question](https://codeforces.com/problemset/problem/1985/C) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20C%20-%20Good%20Prefixes)
| 333 | 1985 D | Manhattan Circle | [Question](https://codeforces.com/problemset/problem/1985/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20D%20-%20Manhattan%20Circle)
| 334 | 1985 E | Secret Box | [Question](https://codeforces.com/problemset/problem/1985/E) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1985%20E%20-%20Secret%20Box)