This commit is contained in:
ShazidMahsrafi 2024-06-01 19:38:08 +06:00
parent 8e0b266601
commit 164f041317
4 changed files with 98 additions and 0 deletions

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()
{
int n;
string s;
cin>>n>>s;
for(int i=1; i<n; ++i)
{
if(s[i]<s[i-1])
{
cout<<"NO\n";
return;
}
}
cout<<"YES\n";
}
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,36 @@
#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;
vector<ll>a(n),b(n+1);
for(auto &i: a) cin>>i;
for(auto &i: b) cin>>i;
ll ans=0, diff=1e18;
for(ll i=0; i<n; ++i)
{
ans += abs(a[i]-b[i]);
diff = min(diff, abs(b[n]-a[i]));
diff = min(diff, abs(b[n]-b[i]));
if(b[n]>=min(a[i],b[i]) && b[n]<=max(a[i],b[i]))
diff = 0;
}
cout<<ans+1+diff<<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,26 @@
#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 l,r;
cin>>l>>r;
if(r&1) r--;
ll ans =log2(r);
cout<<ans<<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

@ -326,6 +326,9 @@ This repository contains my solutions of Codeforces problems. They are in C++ la
| 314 | 1971 D | Binary Cut | [Question](https://codeforces.com/problemset/problem/1971/D) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1971%20D%20-%20Binary%20Cut)
| 315 | 1971 E | Find the Car | [Question](https://codeforces.com/problemset/problem/1971/E) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1971%20E%20-%20Find%20the%20Car)
| 316 | 1971 F | Circle Perimeter | [Question](https://codeforces.com/problemset/problem/1971/F) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1971%20F%20-%20Circle%20Perimeter)
| 317 | 1976 A | Verify Password | [Question](https://codeforces.com/problemset/problem/1976/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1976%20A%20-%20Verify%20Password)
| 318 | 1976 B | Increase Decrease Copy | [Question](https://codeforces.com/problemset/problem/1976/B) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/tree/master/Codes/1976%20B%20-%20Increase%20Decrease%20Copy)
| 319 | 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)