codesolvediscuss | Unsorted

Telegram-канал codesolvediscuss - Codeforces solutions | CodeSolve | discussion

1582

Subscribe to a channel

Codeforces solutions | CodeSolve | discussion

can you give me hint B

Читать полностью…

Codeforces solutions | CodeSolve | discussion

have you try G? g is easier than f

Читать полностью…

Codeforces solutions | CodeSolve | discussion

M direct E solve krne gya bhai alt accnt h

Читать полностью…

Codeforces solutions | CodeSolve | discussion

Na maine contest ni diya main s, to alt s E kra

Читать полностью…

Codeforces solutions | CodeSolve | discussion

Please send g ? Anyone

Читать полностью…

Codeforces solutions | CodeSolve | discussion

ans is range gcd from l+1 to r of the array b

Читать полностью…

Codeforces solutions | CodeSolve | discussion

C , D SOLUTIONS WERE SENT✅✅✅

Читать полностью…

Codeforces solutions | CodeSolve | discussion

#include <bits/stdc++.h>
using namespace std;

int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
string n;
cin >> n;
long long initial_sum = 0;
int c2 = 0, c3 = 0;
for(char ch : n){
int digit = ch - '0';
initial_sum += digit;
if(digit == 2) c2++;
if(digit == 3) c3++;
}
long long target = (9 - (initial_sum %9)) %9;
bool possible = false;
// Iterate through possible b (number of 3s to replace)
for(int b=0; b<=c3; b++){
// Calculate the residual needed after replacing b 3s
long long temp = (target - 6LL * b) % 9;
if(temp < 0) temp += 9;
// Solve 2*a ≡ temp mod9
// The inverse of 2 mod9 is 5 since 2*5=10≡1 mod9
long long a = (temp * 5) % 9;
// Now, a can be a + 9k where a + 9k <= c2
// Since c2 <=1e5 and a <9, check if a <=c2
if(a <= c2){
// Additionally, check if a + 9k <=c2 for some k
// Since a <=c2, it's possible to have a <=c2
possible = true;
break;
}
}
if(possible){
cout << "YES\n";
}
else{
cout << "NO\n";
}
}
}

Codeforces C sol

Читать полностью…

Codeforces solutions | CodeSolve | discussion

CF 🔥‼️
C  DONE ✅ ✅
C  DONE ✅✅

D.  DONE ✅✅
D.  DONE ✅✅


Dmm @codercpp001

Читать полностью…

Codeforces solutions | CodeSolve | discussion

bhai ye wrong de rha h

Читать полностью…

Codeforces solutions | CodeSolve | discussion

All code are correct bro

Читать полностью…

Codeforces solutions | CodeSolve | discussion

CF 🔥🔥

C   DONE ✅✅
C.  done ✅ ✅

D1  DONE ✅ ✅
D1. DONE ✅ ✅
D1. DONE ✅✅
D1. DONE ✅✅

DMM ⏩

Any code upto d1 in 15
Any code upto d1 in 15

@codercpp001

Читать полностью…

Codeforces solutions | CodeSolve | discussion

#include<bits/stdc++.h>
#include<fstream>
using namespace std;
const int mxn = 1e5 + 5, inf = 1e9 + 7;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
int a[mxn + 1];
void solve(){
   cin >> n;
   for(int i = 1; i <= n; i++)cin >> a[i];
   int ans = inf;
   for(int i = 1; i <= n; i++){
       int cnt = 0;
       for(int j = i + 1; j <= n; j++){
           cnt += (a[j] > a[i]);
       }
       ans = min(ans, cnt + (i - 1));
   }
   cout << ans << "\n";
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   
    int tt; cin >> tt;
    while(tt--){
        solve();
    }
    return(0);
}

B sol

Читать полностью…

Codeforces solutions | CodeSolve | discussion

If not solution please give hint. I am stuck on corner cases.

Читать полностью…

Codeforces solutions | CodeSolve | discussion

i solved b and need c if any one will trade dm me

Читать полностью…

Codeforces solutions | CodeSolve | discussion

F ke lie bta de bhai

Читать полностью…

Codeforces solutions | CodeSolve | discussion

E:
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
   
    int t;
    cin >> t;
   
    while(t--){
        string a, b, c;
        cin >> a >> b >> c;
       
        int n = a.size();
        int m = b.size();
       
        // Initialize DP table with (n+1) x (m+1) dimensions
        // Using a vector of vectors for flexibility
        // Initialize all values to a large number
        const int INF = 1e9;
        vector<vector<int>> dp(n + 1, vector<int>(m + 1, INF));
       
        // Base case: both a and b are empty
        dp[0][0] = 0;
       
        // Fill the DP table
        for(int i = 0; i <= n; ++i){
            for(int j = 0; j <= m; ++j){
                if(i == 0 && j == 0) continue;
                // Current position in c is (i + j -1)
                int pos = i + j -1;
                if(pos >= c.size()){
                    // This should not happen as |c| = |a| + |b|
                    continue;
                }
                // If we take a character from a
                if(i > 0){
                    int cost = dp[i-1][j];
                    if(a[i-1] != c[pos]){
                        cost +=1;
                    }
                    dp[i][j] = min(dp[i][j], cost);
                }
                // If we take a character from b
                if(j > 0){
                    int cost = dp[i][j-1];
                    if(b[j-1] != c[pos]){
                        cost +=1;
                    }
                    dp[i][j] = min(dp[i][j], cost);
                }
            }
        }
       
        // The answer is dp[n][m]
        cout << dp[n][m] << "\n";
    }
}

CF E SOLUTION

Читать полностью…

Codeforces solutions | CodeSolve | discussion

Bhai E dp h 🥲, ab to Lelo koi mujhse

Читать полностью…

Codeforces solutions | CodeSolve | discussion

E h merepe kisi ko chiye ?

Читать полностью…

Codeforces solutions | CodeSolve | discussion

caculate using seg tree or sprase table

Читать полностью…

Codeforces solutions | CodeSolve | discussion

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
   
    ll even = 0, odd = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(i % 2) odd += a[i];
        else even += a[i];
    }
   
    ll target = (even + odd) / n;
   
    if((even + odd) % n != 0) {
        cout << "NO\n";
        return;
    }
   
    ll req_even = target * ((n + 1) / 2);
    ll req_odd = target * (n / 2);
   
    if(even == req_even && odd == req_odd) cout << "YES\n";
    else cout << "NO\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
   
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}

B sol

Читать полностью…

Codeforces solutions | CodeSolve | discussion

#include <bits/stdc++.h>
using namespace std;

int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
string s;
cin >> s;
// Convert string to a mutable vector of integers
vector<int> digits(s.size());
for(int i=0; i<s.size(); i++) digits[i] = s[i] - '0';

// Iterate from left to right
for(int i=1; i<digits.size(); i++){
// While current digit can be swapped left to increase the left digit
while(i >=1 && digits[i] > digits[i-1] +1 && digits[i] >0){
// Perform the operation: swap digits[i] and digits[i-1], after decreasing digits[i] by 1
int temp = digits[i];
digits[i] = digits[i-1];
digits[i-1] = temp -1;
// Move one position to the left to check for further possible operations
if(i >1) i--;
else break;
}
}
// Convert digits back to string
string res = "";
for(int d : digits) res += to_string(d);
cout << res << "\n";
}
}
Codeforces D sol

Читать полностью…

Codeforces solutions | CodeSolve | discussion

CODEFORCES DIV 3 ️‍🔥️‍🔥
DM FAST

D.  DONE ✅✅
D.  DONE ✅✅

E.   DONE ✅✅
E.    DONE ✅✅
E.   DONE ✅✅


DM FAST @codercpp001

Читать полностью…

Codeforces solutions | CodeSolve | discussion

CF 🔥‼️

A DONE ✅✅

B DONE ✅✅
B DONE ✅✅


C  DONE ✅ ✅
C  DONE ✅ ✅
C  DONE ✅ ✅


Dmm @codercpp001

Читать полностью…

Codeforces solutions | CodeSolve | discussion

#include <bits/stdc++.h>
using namespace std;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);


int t;
cin >> t;

while (t--) {

int n;
cin >> n;

vector<pair<long long, int>> p(n + 1);

for (int i = 1; i <= n; i++) {
cin >> p[i].first;
p[i].first += i - 1;
p[i].second = 0;
}

p[1].first = 0;
sort(p.begin(), p.end());

map<long long, bool> m;
m[n] = true;

for (int i = 2; i <= n; i++) {
if (m[p[i].first])
m[p[i].first + p[i].second] = true;
}

long long r = 0;
for (const auto& [x, y] : m)
if (y)
r = x;

cout << r << "\n";

}
}

Читать полностью…

Codeforces solutions | CodeSolve | discussion

bhai iska ye solution work nhi kr rha hgala output de rha h

Читать полностью…

Codeforces solutions | CodeSolve | discussion

I need help in cred. Assignment

Читать полностью…

Codeforces solutions | CodeSolve | discussion

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
int mod = 1e9 + 7;


void solution() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
std::vector<int>arr(n) ;
for(int i=0; i<n; i++){
cin>>arr[i];
}
int bpnt;
bool fl = 0;
for(int i=1; i<n; i++){
if(arr[i] < arr[i-1]){
bpnt =i-1;
fl=1;
break;
}
}

int cnt = bpnt;
while(upper_bound(arr.begin() , arr.end() , arr[bpnt]) != arr.end()){
int k = upper_bound(arr.begin() , arr.end() , arr[bpnt]) - arr.begin();
arr[k] = -1;
cnt++;
}
cout<<cnt<<'\n';
}
}

signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solution();
return 0;
}

Читать полностью…

Codeforces solutions | CodeSolve | discussion

#include <bits/stdc++.h>
using namespace std;

void solve(){
int n;
cin >> n;

vector<pair<long long, int> > a(n + 1);

for (int i = 1; i <= n; i ++){
cin >> a[i].first;
a[i].first += i - 1;
a[i].second = i - 1;
}

a[1].first = 0;
sort(a.begin(), a.end());
map<long long, bool> dp;
dp[n] = true;

for (int i = 2; i <= n; i ++){
if (dp[a[i].first])
dp[a[i].first + a[i].second] = true;
}

long long ans = 0;

for (auto [x, y] : dp)
if (y)
ans = x;

cout << ans << "\n";
}

int main(){
ios::sync_with_stdio(0);
cin.tie(0);

int tests;
cin >> tests;

while (tests --)
solve();

return 0;
}

Читать полностью…

Codeforces solutions | CodeSolve | discussion

CF 🔥🔥

B.   DONE ✅✅
C.  done ✅ ✅

D1  DONE ✅ ✅
D1. DONE ✅ ✅
D1. DONE ✅✅
D1. DONE ✅✅

DMM ⏩


@codercpp001

Читать полностью…
Subscribe to a channel