Yesterday even after solving three problems i got a delta negative which doesn,t usually happens when you solve three questions at the rating where i am so i searched for telegram channels and guess what i found, I found a telegram channel with over 3300 members, I don,t want to write the name here for obvious reasons, here are some of the solutions that were floating there
Solutions of C:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>
using namespace std;
void maximizeGoodPairs(string &s) {
int n = s.size();
unordered_map<char, int> freq;
for (char c : s) {
freq[c]++;
}
string result(n, ' ');
int idx = 0;
while (true) {
bool filled = false;
for (auto &[ch, count] : freq) {
if (count > 0) {
result[idx] = ch;
idx++;
count--;
filled = true;
if (idx >= n) {
idx = 1;
}
}
}
if (!filled) {
break;
}
}
cout << result << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
maximizeGoodPairs(s);
}
return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void solve() {
int n;
string s;
cin >> n >> s;
vector<int> freq(26, 0);
// Count frequency of each character
for (char c : s) {
freq[c - 'a']++;
}
string even, odd;
// Fill two separate strings: one for even index positions and one for odd index positions
for (int i = 0; i < 26; ++i) {
if (freq[i] > 0) {
string chars(freq[i], 'a' + i);
if (even.size() <= odd.size()) {
even += chars;
} else {
odd += chars;
}
}
}
// Now alternate between even and odd strings
string result;
int i = 0, j = 0;
while (i < even.size() || j < odd.size()) {
if (i < even.size()) result += even[i++];
if (j < odd.size()) result += odd[j++];
}
cout << result << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Solution of D1:
#include <iostream>
#include <unordered_set>
#include <sstream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tes;
cin >> tes;
ostringstream sb;
while (tes--) {
int que;
long long m;
cin >> que >> m;
int max_val = 0;
while (que--) {
int n;
cin >> n;
unordered_set<int> set;
int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
set.insert(a[i]);
}
int first = 0;
while (true) {
if (set.find(first) == set.end()) {
set.insert(first);
break;
}
++first;
}
while (true) {
if (set.find(first) == set.end()) {
max_val = max(max_val, first);
break;
}
++first;
}
}
if (m >= max_val) {
long long ans = (long long)max_val * (max_val + 1);
long long big = (m * (m + 1)) / 2 - ans / 2;
sb << (ans + big) << '\n';
} else {
long long ans = (long long)max_val * (m + 1);
sb << ans << '\n';
}
}
cout << sb.str();
return 0;
}
Solution of D2:
#include<bits/stdc++.h> using namespace std; #dPfinn int long long int sum(int x) { return x*(x+1) ; } int interval(int I,int r) { return sum(r)-sum(I-1); } vector<int> son[1000001]; int dp[1000001]; void solve() int n,m,s=0,mint=0; map<int,int> cnt; cin B; n B; m; for(int i=1,u,v;i<=n;++0 { int I; cin B; I; set<int> t; for(int i=1,x;i<=1;++0 { cin B; x; t.insert(x); } bool flag=true; for(int i=0;;++i) { if(!t.count(i)) { if(flag) { flag=false; u=i; mint=max(mint,u); } else { v=i; break;}
}
} s=max(s,v);
son[v].push_back(u);
cnt[u]++;
} for(int i=0; i<=s; ++0 dp[i]=-1; for(int i=s; i>=0; --i) if(dp[i]==-1) dp[i]=i; for(int j:son[i]) dp[j]=max(dp[j],dp[i]);
} int pp=0; for(int i=0; i<=s; ++0 if(i<=mint) dp[i]=max(dp[i],mint); for(auto i:cnt) if(i.second>=2) pp=max(pp,dp[i.first]);
} for(int i=0; i<=s; ++0 dp[i]=max(dp[i],pp); for(int i=0; i<=s; ++0 son[i].clear(); if(m<=s) int sum=0; for(int i=0; i<=m; ++0 sum+=dp[i]; cout B+ sum B+ endl; return;
} int sum=0; for(int i=0; i<=s; ++0 sum+=dp[i]; sum+=interval(s+1,m); cout B+ sum B+ endl;
} signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int t;cin>>t;
while(t--)solve()
above D2 sol if rewritten using GPT
#include <bits/stdc++.h>
using namespace std;
#define int long long
int sum(int x) {
return x * (x + 1) / 2; // Corrected the sum formula
}
int interval(int I, int r) {
return sum(r) - sum(I - 1);
}
vector<int> son[1000001];
int dp[1000001];
void solve() {
int n, m, s = 0, mint = 0;
map<int, int> cnt;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
int l;
cin >> l;
set<int> t;
for (int j = 1; j <= l; ++j) {
int x;
cin >> x;
t.insert(x);
}
bool flag = true;
int u, v;
for (int j = 0;; ++j) {
if (!t.count(j)) {
if (flag) {
flag = false;
u = j;
mint = max(mint, u);
} else {
v = j;
break;
}
}
}
s = max(s, v);
son[v].push_back(u);
cnt[u]++;
}
for (int i = 0; i <= s; ++i) {
dp[i] = -1;
}
for (int i = s; i >= 0; --i) {
if (dp[i] == -1) dp[i] = i;
for (int j : son[i]) {
dp[j] = max(dp[j], dp[i]);
}
}
int pp = 0;
for (int i = 0; i <= s; ++i) {
if (i <= mint) dp[i] = max(dp[i], mint);
}
for (auto i : cnt) {
if (i.second >= 2) pp = max(pp, dp[i.first]);
}
for (int i = 0; i <= s; ++i) {
dp[i] = max(dp[i], pp);
}
for (int i = 0; i <= s; ++i) {
son[i].clear();
}
if (m <= s) {
int sum = 0;
for (int i = 0; i <= m; ++i) {
sum += dp[i];
}
cout << sum << endl;
return;
}
int sum = 0;
for (int i = 0; i <= s; ++i) {
sum += dp[i];
}
sum += interval(s + 1, m);
cout << sum << endl;
}
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int t;
cin >> t;
while (t--) solve();
return 0;
}
please zltzlt and Mike Mirzayanov do the testing again and ban all the accounts with these and similar solutions. Thank you and Please mind my mistakes in formatting and english as this is my first blog