-
Notifications
You must be signed in to change notification settings - Fork 103
/
abcdef.cpp
40 lines (40 loc) · 1.02 KB
/
abcdef.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 2014-04-25
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int a[100];
int main() {
int N;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", a+i);
}
vector<int> s1, s2;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) {
s1.push_back(a[i]*a[j]+a[k]);
if (a[i] != 0) {
s2.push_back(a[i]*(a[j]+a[k]));
}
}
}
}
sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());
long long res = 0; int i = 0, j = 0;
while (i < s1.size() && j < s2.size()) {
if (s1[i] < s2[j]) {
i++;
} else if (s1[i] > s2[j]) {
j++;
} else {
int k, m;
for (k = i; k < s1.size() && s1[k] == s1[i]; k++);
for (m = j; m < s2.size() && s2[m] == s2[j]; m++);
res += (k-i)*(long long)(m-j); i = k; j = m;
}
}
printf("%lld\n", res);
}