Maximum Palindromes

  • + 0 comments

    1.can anybody tell why m i failing with some test cases.

      -
    #include <iostream>
    #include <memory.h>
    #include <vector>
    #define mod % 1000000007
    using namespace std;
    #define ll long long
    ll int cal(vector<vector<ll int>>  &dp,vector<ll int> &fact,ll int l,ll int r)
    {
        
        ll int len=0;
        ll int odd=0;
        vector<ll int> v(26,0);
        for(int i=0;i<26;i++)
        { len += (dp[r][i]-dp[l-1][i])/2;
          //cout<<"\n len = "<<len;
           v[i]=(dp[r][i]-dp[l-1][i])/2;
           if((dp[r][i]-dp[l-1][i])%2)
              odd++;
        }
         ll int ans=fact[len];
         ll int d=1;
        for(int i=0;i<26;i++)
        {d*=fact[v[i]] % 1000000007; 
         d= d mod;
        }
         ans = (ans*max((ll int)1,odd))mod;
         d= ans/d;
        return d%1000000007;
    }
    int main() {
         string s;
         cin>>s;
         vector<vector<ll int>>  dp;
         dp.resize(s.size() + 1);
         for(ll int i=0;i<=s.size();i++)
         dp[i].resize(26);  
         
         for(int i=0 ; i < s.size();i++)
             dp[i+1][s[i]-'a']++;
         
         for(ll int i=0;i<26;i++)
         for(ll int j=1;j<=s.size();j++)
            dp[j][i]+=dp[j-1][i]; 
          
        vector<ll int > fact(100001,0);
        fact[0]=1;
        for(int i=1;i<=100000;i++)
            fact[i]=(fact[i-1]*i)mod;
        ll int q;
        cin>>q;
        while(q--)
        {
            ll int l,r;
            cin>>l>>r;
            cout<<cal(dp,fact,l,r)<<endl;
            
        }
        
    }