Help with segmentation fault in Codeforces #634 div 3 Palindrome Block E2 Help needed ! For testcase 9

Last made submission is for this problem please have a look and help

using namespace std;

int mod= 1e9+7;

int powerMod(int a, int b){ if(b==0){ return 1; } if(a%2==0){ return powerMod((aa)%mod, b/2); } --b; return ( a * powerMod((aa)%mod, b/2) )%mod ; }

int gcd(int a, int b){ return __gcd(a,b); }

int32_t main(){

int T=1;
cin>>T;

while(T--){
    int n;
    cin>>n;
    int a[n];
    vector<int>v[205];
    int f[n][205];
    //memset(f,0,sizeof(f));
    for(int i=0;i<n;i++){
        for(int j=0;j<=200;j++){
            f[i][j]=0;
        }
    }
    vector<int>mp(n,0);
    for(int i=0;i<n;i++){
       cin>>a[i];
       v[a[i]].push_back(i);
       if(i>0){
         for(int j=1;j<=200;j++){
          f[i][j]=f[i-1][j];
         }
       }
       f[i][a[i]]++;
       mp[i]=f[i][a[i]];
    }
    int ans=1;

    for(int i=0;i<n;i++){
       int cnt= mp[i], sz=v[a[i]].size();
       if(cnt*2 > sz){
         continue;
       }
       int x=v[a[i]][cnt-1];
       int y=v[a[i]][sz-cnt];
       int mx=0;
       for(int j=1;j<=200;j++){
         if(j==a[i]){
          mx=max(mx,f[y][j]-f[x][j]-1);
         }
         else
          mx=max(mx,f[y][j]-f[x][j]);
       }
       ans=max(ans,mx+cnt*2);
    }

    cout<<ans<<'\n';

}

return 0;

}

Remove #define int long long and It will pass. I am not sure but I think this should show memory limit exceed error because after removing long long it got passed.

1 Like

Thanks a lot @souraavv buddy it worked