-
Notifications
You must be signed in to change notification settings - Fork 21
/
CCPC中南邀请赛H.cpp
75 lines (63 loc) · 1004 Bytes
/
CCPC中南邀请赛H.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#define endl '\n'
using namespace std;
const int MAXN = 1e5 + 5;
int n,m;
int a[MAXN],b[MAXN];
int ra[MAXN],rb[MAXN];
int va[MAXN * 10],vb[MAXN * 10];
int judge(int x,int y)
{
return floor(sqrt((double)abs(x - y)));
}
int main()
{
while(scanf("%d %d",&n,&m) == 2)
{
memset(va,0,sizeof(va));
memset(vb,0,sizeof(vb));
int i;
for(i = 0;i < n;i++)
{
scanf("%d",&a[i]);
}
int ca = 0,cb = 0;
for(i = 0;i < n;i++)
{
if(va[a[i]] == 0)
{
ra[ca++] = a[i];
}
va[a[i]]++;
}
for(i = 0;i < m;i++)
{
scanf("%d",&b[i]);
}
for(i = 0;i < m;i++)
{
if(vb[b[i]] == 0)
{
rb[cb++] = b[i];
}
vb[b[i]]++;
}
long long ans = 0;
int j;
for(i = 0;i < ca;i++)
{
for(j = 0;j < cb;j++)
{
ans += judge(ra[i],rb[j]) * va[ra[i]] * vb[rb[j]];
}
}
cout << ans << endl;
}
return 0;
}