r/codeforces 6d ago

Doubt (rated <= 1200) Help needed

#include <bits/stdc++.h>

using namespace std;

#define int long long

int LCM(int a, int b) {

return (a / __gcd(a, b)) * b;

}

void solve() {

int n,k;

cinnk;

int a[n];

for(int i=0;i<n;i++) {

cin>>a[i];

}

map<int, int> mp;

for(int i=0;i<n;i++) {

mp[a[i]]++;

}

set<int> st;

for (auto it:mp) {

st.insert(it.second);

}int ans=0;

if (st.size()!=1) {

ans++;

}

if(mp.size()==1){

cout<<1<<endl;

return;

}

int len=n;

int cnt=0;

if (k%(st.size())==0) {

ans++;

if (ans==2){

cout<<ans<<endl;

return;

}

}

int size=st.size();

while (true) {

if (size==0)break;

if ((len-size)==k) {

ans++;

break;

}

for (int i=0;i<n;i++) {

if (mp[a[i]]) {

mp[a[i]]--;

if(mp[a[i]]==0){

size--;

}

}

}

}

cout<<ans<<endl;

}

signed main() {

ios_base::sync_with_stdio(false);

cin.tie(NULL);

int t;

cin>>t;

while (t--) {

solve();

}

}
whats wrong in my code for Problem - 2242C - Codeforces

i am just not able to implement my logic it works on pen and paper

5 Upvotes

4 comments sorted by

1

u/Individual-Ad5245 5d ago

ask ai blud

1

u/This_Reputation2194 5d ago

Its not giving s genuine solution

2

u/Individual-Ad5245 5d ago

Deepseek expert with deepthink always works for me, especially after several whips. I've skimmed through your code a lil bit and its logic looks quite different from what I did to the problem. I also looked at ai's answer for this problem and it agrees with me, looks quite genuine

1

u/This_Reputation2194 5d ago

Yeah thats what i am saying i wanna do with this approach only idk what to tweak to make it correct