#include <bits/stdc++.h>
using namespace std;`Preformatted text`
#define for0(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define tc(t) int t;cin >>t;while(t--)
#define ll long long int
#define pb(i) push_back(i)
#define mod 1000000007
#define line "\n"
ll fact(ll i) {
if (i <= 1) return 1;
else return i * fact(i - 1);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
tc(t) {
ll n;
cin>>n;
if(n==1){
cout<<0<<line;
continue;
}
map<ll, ll> m;
for (int i = 0; i < n; i++) {
ll temp;
cin >> temp;
m[temp]++;
}
ll sum = 0, temp = 0,len=m.size();
for (auto it : m) {
if (it.second > 1) {
ll x=it.second;
sum += (fact(x) / fact(x-2));
}
// cout<<sum<<line;
// cout<<it.first<<" "<<it.second<<line;
}
// temp=fact(n)/fact(n-2);
cout << temp-sum << line;
}
return 0;
}
Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile!
Also: what Problem are you trying to solve, or what testcase is causing the runtime error?
I am trying to solve Beautiful Pair problem from July Lunchtime.
Exactly the same problem as this guy:
so what happened it runs correctly
Really? Not for me, it doesn’t:
[~/devel/hackerrank/otherpeoples]> g++ -std=c++14 deadline_11-BUTYPAIR.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE
deadline_11-BUTYPAIR.cpp: In function ‘int main()’:
deadline_11-BUTYPAIR.cpp:33:24: warning: unused variable ‘len’ [-Wunused-variable]
ll sum = 0, temp = 0,len=m.size();
^~~
[simon@simon-laptop][09:43:02]
[~/devel/hackerrank/otherpeoples]>cat BUYTPAIR-testcase-large.txt | ./a.out
Floating point exception (core dumped)
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)