-
Notifications
You must be signed in to change notification settings - Fork 16
/
Adding_Squares.cpp
78 lines (78 loc) · 1.54 KB
/
Adding_Squares.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
76
77
78
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
typedef pair<int,int> pp;
bool com(pp x,pp y){
return x.ff<y.ff;
}
ll power(ll x,ll y){
ll prod=1;
while(y){
if(y&1) prod=(prod*x)%mod;
x=(x*x)%mod;
y/=2;
}
return prod;
}
const int N=1e5+9;
void solve(){
int w,h,n,m;
cin>>w>>h>>n>>m;
int a[n],b[m];
vector<int> vis(N,0);
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<m;i++) cin>>b[i],vis[b[i]]=1;
sort(a,a+n);
sort(b,b+m);
bitset<N> x,y,bit;
for(int i=1;i<n;i++){
bit=(bit<<(a[i]-a[i-1]));
bit[a[i]-a[i-1]]=1;
x|=bit;
}
int flag=0;
//for(int i=0;i<c.size();i++) x[c[i]]=1;
int ans=0;
bit.reset();
for(int i=1;i<m;i++){
bit=bit<<(b[i]-b[i-1]);
bit[b[i]-b[i-1]]=1;
y|=bit;
}
for(int i=0;i<=max(h,w);i++){
if(x[i]&&x[i]==y[i]){
ans++;
x[i]=0;
}
}
int sum=ans;
bitset<N> v;
for(int i=0;i<=h;i++){
if(vis[i]) continue;
v.reset();
for(int j=0;j<m;j++){
if(x[abs(b[j]-i)]) v[abs(b[j]-i)]=1;
}
ans=max(ans,sum+(int)(v.count()));
}
cout<<ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
//cin>>t;
while(t--)
solve();
return 0;
}
/*
3 5 8 9 12 15
3 3 1 3 3
3 6 7 10 13
*/