why it is showing wrong ans in test case 3 and 4 but showing correct in all other cases
Wa in some test cases
Please send your code link.
#include<bits/stdc++.h> using namespace std; #define ll long long int #define f(i,n) for(i=0;i<n;i++) #define f1(i,n) for(i=1;i<=n;i++) int unique(vectorv,vector&dp){ int i; int sz=v.size(); map<int,int>prevind; f1(i,sz-1){ prevind[v[i]]=0; } dp[1]=1; prevind[v[1]]=1; f1(i,sz-1){ dp[i+1]=dp[i]+(i+1-prevind[v[i+1]]); prevind[v[i+1]]=i+1; } int sum=0; f1(i,sz-1) sum+=dp[i]; return sum; } main(){ int n; cin>>n; int i; vectorv(n+1); vectordp(n+1); f1(i,n) cin>>v[i]; float ans=unique(v,dp); ans=float(2ans-n)/(nn); cout<<fixed<<setprecision(6)<<ans; }
Please don’t send raw code.
Paste your code on ide.codingblocks.com and then after saving send the generated link.
As I did not get any respond from your side, I am closing this thread.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.