We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
1.can anybody tell why m i failing with some test cases.
-
#include<iostream>#include<memory.h>#include<vector>#define mod % 1000000007usingnamespacestd;#define ll long longllintcal(vector<vector<llint>>&dp,vector<llint>&fact,llintl,llintr){llintlen=0;llintodd=0;vector<llint>v(26,0);for(inti=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++;}llintans=fact[len];llintd=1;for(inti=0;i<26;i++){d*=fact[v[i]]%1000000007;d=dmod;}ans=(ans*max((llint)1,odd))mod;d=ans/d;returnd%1000000007;}intmain(){strings;cin>>s;vector<vector<llint>>dp;dp.resize(s.size()+1);for(llinti=0;i<=s.size();i++)dp[i].resize(26);for(inti=0;i<s.size();i++)dp[i+1][s[i]-'a']++;for(llinti=0;i<26;i++)for(llintj=1;j<=s.size();j++)dp[j][i]+=dp[j-1][i];vector<llint>fact(100001,0);fact[0]=1;for(inti=1;i<=100000;i++)fact[i]=(fact[i-1]*i)mod;llintq;cin>>q;while(q--){llintl,r;cin>>l>>r;cout<<cal(dp,fact,l,r)<<endl;}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Palindromes
You are viewing a single comment's thread. Return to all comments →
1.can anybody tell why m i failing with some test cases.
-