๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.62K subscribers
5.61K photos
3 videos
95 files
10.6K 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
๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
Photo
#include<bits/stdc++.h>
using namespace std;

int memoize(int l, int r, int residue, const vector<char>& colors) {
    int n = colors.size();
    int dp[n][n][n];
    memset(dp, -1, sizeof(dp));

    if (r < l)
        return 0;
    else if (dp[l][r][residue] != -1)
        return dp[l][r][residue];

    dp[l][r][residue] = (residue + 1) * (residue + 1) + memoize(l, r - 1, 0, colors);

    for (int i = l; i < r; i++) {
        if (colors[i] == colors[r]) {
            dp[l][r][residue] = max(dp[l][r][residue], memoize(l, i - 1, 0, colors) + memoize(i + 1, r, residue + 1, colors));
        }
    }

    return dp[l][r][residue];
}

int solve(int n, vector<char> colors) {
    return memoize(0, n - 1, 0, colors);
}

int main() {
    int n;
    cin >> n;
    vector<char> colors(n);
    for (int i = 0; i < n; i++) {
        cin >> colors[i];
    }
    cout << solve(n, colors);
    return 0;
}

Crayon Removal Scoring Game โœ…
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        long long x, y;
        cin >> x >> y;
        if (y > x) {
            cout << 2 << '\n';
        } else if (y >= 2 && x - y >= 2) {
            cout << 3 << '\n';
        } else {
            cout << -1 << '\n';
        }
    }
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    if(!(cin >> t)) return 0;
    while (t--) {
        int n;
        cin >> n;
        int m = 2 * n;
        vector<int> a(m + 1, 0);
        vector<char> used(m + 1, 0);
        int cur = 1;
        for (int x = n; x >= 1; --x) {
            while (used[cur]) ++cur;
            int i = cur;
            int j = i + x;
            while (j <= m && used[j]) j += x;
            a[i] = a[j] = x;
            used[i] = used[j] = 1;
        }
        for (int i = 1; i <= m; ++i) {
            if (i > 1) cout << ' ';
            cout << a[i];
        }
        cout << '\n';
    }
    return 0;
}

B