Problem Link
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int arr[105];
int n, a, b, c, d, e, f, g;
vector<long> lhs; // lhs stores result of a * b + c
vector<long> rhs; // rhs stores result of d * (e + f)
cin >> n;
for(int i = 0; i < n; i++){
cin >> arr[i];
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
for(int k = 0; k < n; k++){
a = arr[i];
b = arr[j];
c = arr[k];
d = arr[i];
e = arr[j];
f = arr[k];
lhs.push_back((a * b) + c);
if(d != 0){
rhs.push_back(d * (e + f));
}
}
}
}
sort(lhs.begin(), lhs.end());
sort(rhs.begin(), rhs.end());
vector<long>::iterator it, l1, l2, u1, u2;
it = lhs.begin();
long result = 0;
while(it != lhs.end()){
l1 = lower_bound(lhs.begin(), lhs.end(), *it);
u1 = upper_bound(lhs.begin(), lhs.end(), *it);
l2 = lower_bound(rhs.begin(), rhs.end(), *it);
u2 = upper_bound(rhs.begin(), rhs.end(), *it);
result += (u1 - l1) * (u2 - l2);
it = u1;
}
cout << result << endl;
return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int arr[105];
int n, a, b, c, d, e, f, g;
vector<long> lhs; // lhs stores result of a * b + c
vector<long> rhs; // rhs stores result of d * (e + f)
cin >> n;
for(int i = 0; i < n; i++){
cin >> arr[i];
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
for(int k = 0; k < n; k++){
a = arr[i];
b = arr[j];
c = arr[k];
d = arr[i];
e = arr[j];
f = arr[k];
lhs.push_back((a * b) + c);
if(d != 0){
rhs.push_back(d * (e + f));
}
}
}
}
sort(lhs.begin(), lhs.end());
sort(rhs.begin(), rhs.end());
vector<long>::iterator it, l1, l2, u1, u2;
it = lhs.begin();
long result = 0;
while(it != lhs.end()){
l1 = lower_bound(lhs.begin(), lhs.end(), *it);
u1 = upper_bound(lhs.begin(), lhs.end(), *it);
l2 = lower_bound(rhs.begin(), rhs.end(), *it);
u2 = upper_bound(rhs.begin(), rhs.end(), *it);
result += (u1 - l1) * (u2 - l2);
it = u1;
}
cout << result << endl;
return 0;
}
Comments
Post a Comment