๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.52K subscribers
5.56K photos
3 videos
95 files
9.67K links
๐ŸšฉMain Group - @SuperExams
๐Ÿ“Job Updates - @FresherEarth

๐Ÿ”ฐAuthentic Coding Solutions(with Outputs)
โš ๏ธDaily Job Updates
โš ๏ธHackathon Updates & Solutions

Buy ads: https://telega.io/c/cs_algo
Download Telegram
#include <bits/stdc++.h>
using namespace std;
int findMinimumMoves(int C, int N) {
    vector<vector<int>> dp(C + 1, vector<int>(N + 1, 0));
    for (int n = 0; n <= N; n++) dp[1][n] = n;
    for (int c = 1; c <= C; c++) dp[c][0] = 0;
    for (int c = 2; c <= C; c++) {
        for (int n = 1; n <= N; n++) {
            int low = 1, high = n, result = n;
            while (low <= high) {
                int mid = (low + high) / 2;
                int breakCase = dp[c-1][mid-1]; 
                int noBreakCase = dp[c][n-mid]; 
                int worstCase = 1 + max(breakCase, noBreakCase);
                result = min(result, worstCase);
                if (breakCase > noBreakCase) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            dp[c][n] = result;
        }
    }

    return dp[C][N];
}

int main() {
    int C, N;
    cin >> C >> N;
    cout << findMinimumMoves(C, N) << endl;
    return 0;
}


Kickdrum โœ…
#include<cstdio>
const int N=2e5+1;
long long r;
int i,j,k,n,a[N],f[N][2];
int t,en[N],fa[N],nxt[N];
void dfs(int u,int p)
{
int w=a[u]>>k&1,i=fa[u],v;
for(f[u][w]=1,f[u][w^1]=0;i;i=nxt[i])if((v=en[i])!=p)
{
dfs(v,u);
r+=(1ll*f[v][0]*f[u][1]+1ll*f[v][1]*f[u][0])<<k;
f[u][1]+=f[v][w^1],f[u][0]+=f[v][w];
}
}
int main()
{
scanf("%d",&n);
for(i=1;i<=n;r+=a[i++])
scanf("%d",a+i);
for(k=1;k<n;++k)
{
scanf("%d%d",&i,&j);
en[++t]=j,nxt[t]=fa[i],fa[i]=t;
en[++t]=i,nxt[t]=fa[j],fa[j]=t;
}
for(k=19;~k;--k)dfs(1,0);
printf("%I64d",r);
}

Titan โœ…
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int maxMinDistance(vector<int>& x, int k) {
    sort(x.begin(), x.end());
    int low = 0, high = x.back() - x.front();
    int result = 0;

    while (low <= high) {
        int mid = (low + high) / 2;
        int count = 1;
        int lastPoint = x[0];

        for (int point : x) {
            if (point - lastPoint >= mid) {
                count++;
                lastPoint = point;
            }
        }

        if (count >= k) {
            result = mid;
            low = mid + 1;
        } else {
            high = mid - 1;
        }
    }

    return result;
}

//Optimal points selection โœ