#include <bits/stdc++.h>
#define ll long long
using namespace std;
//legborzalmasabb kod amit valaha lattam
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll n,m,a,b,i,j; cin >> n >> m;
vector<vector<ll>> v(n, vector<ll>(m));
vector<ll> A(n);
for (i = 0; i < n; ++i)
cin >> A[i];
vector<ll> B(m);
for (i = 0; i < m; ++i)
cin >> B[i];
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
v[i][j] = A[i]*B[j];
}
}
int ans = 0;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
if (n>=3 && m>=3)
{
if (i == 0)
{
if (j == 0)
{
if (v[i+1][j] < v[i][j] && v[i][j+1] < v[i][j])
{
ans++;
}
}
else if (j == m-1)
{
if (v[i+1][j] < v[i][j] && v[i][j-1] < v[i][j])
{
ans++;
}
}
else
{
if (v[i+1][j] < v[i][j] && v[i][j-1] < v[i][j] && v[i][j+1] < v[i][j])
{
ans++;
}
}
}
else if (i == n-1)
{
if (j == 0)
{
if (v[i-1][j] < v[i][j] && v[i][j+1] < v[i][j])
{
ans++;
}
}
else if (j == m-1)
{
if (v[i-1][j] < v[i][j] && v[i][j-1] < v[i][j])
{
ans++;
}
}
else
{
if (v[i-1][j] < v[i][j] && v[i][j-1] < v[i][j] && v[i][j+1] < v[i][j])
{
ans++;
}
}
}
else
{
if (j == 0)
{
if (v[i-1][j] < v[i][j] && v[i][j+1] < v[i][j] && v[i+1][j] < v[i][j])
{
ans++;
}
}
else if (j == m-1)
{
if (v[i-1][j] < v[i][j] && v[i][j-1] < v[i][j] && v[i+1][j] < v[i][j])
{
ans++;
}
}
else
{
if (v[i-1][j] < v[i][j] && v[i][j-1] < v[i][j] && v[i][j+1] < v[i][j] && v[i+1][j] < v[i][j])
{
ans++;
}
}
}
}
else if (n == 2 && m>=2)
{
if (i == 0)
{
if (j == 0)
{
if (v[i+1][j] < v[i][j] && v[i][j+1] < v[i][j])
{
ans++;
}
}
else if (j == m-1)
{
if (v[i+1][j] < v[i][j] && v[i][j-1] < v[i][j])
{
ans++;
}
}
else
{
if (v[i+1][j] < v[i][j] && v[i][j-1] < v[i][j] && v[i][j+1] < v[i][j])
{
ans++;
}
}
}
else if (i == n-1)
{
if (j == 0)
{
if (v[i-1][j] < v[i][j] && v[i][j+1] < v[i][j])
{
ans++;
}
}
else if (j == m-1)
{
if (v[i-1][j] < v[i][j] && v[i][j-1] < v[i][j])
{
ans++;
}
}
else
{
if (v[i-1][j] < v[i][j] && v[i][j-1] < v[i][j] && v[i][j+1] < v[i][j])
{
ans++;
}
}
}
}
else if (n >=2 && m == 2)
{
if (i == 0)
{
if (j == 0)
{
if (v[i+1][j] < v[i][j] && v[i][j+1] < v[i][j])
{
ans++;
}
}
else if (j == m-1)
{
if (v[i+1][j] < v[i][j] && v[i][j-1] < v[i][j])
{
ans++;
}
}
}
else if (i == n-1)
{
if (j == 0)
{
if (v[i-1][j] < v[i][j] && v[i][j+1] < v[i][j])
{
ans++;
}
}
else if (j == m-1)
{
if (v[i-1][j] < v[i][j] && v[i][j-1] < v[i][j])
{
ans++;
}
}
}
else
{
if (j == 0)
{
if (v[i-1][j] < v[i][j] && v[i][j+1] < v[i][j] && v[i+1][j] < v[i][j])
{
ans++;
}
}
else if (j == m-1)
{
if (v[i-1][j] < v[i][j] && v[i][j-1] < v[i][j] && v[i+1][j] < v[i][j])
{
ans++;
}
}
}
}
else if (m >= 2 && n == 1)
{
if (j == 0)
{
if (v[i][j+1] < v[i][j])
{
ans++;
}
}
else if (j == m-1)
{
if (v[i][j-1] < v[i][j])
{
ans++;
}
}
else
{
if (v[i][j-1] < v[i][j] && v[i][j+1] < v[i][j])
{
ans++;
}
}
}
else if (m == 1 && n >= 2)
{
if (i == 0)
{
if (v[i+1][j] < v[i][j])
{
ans++;
}
}
else if (i == n-1)
{
if (v[i-1][j] < v[i][j])
{
ans++;
}
}
else
{
if (v[i-1][j] < v[i][j] && v[i+1][j] < v[i][j])
{
ans++;
}
}
}
else if (m == 1 && n == 1)
{
ans++;
}
}
}
cout << ans << endl;
return 0;
}
Részfeladat | Összpont | Teszt | Verdikt | Idő | Memória | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Elfogadva | 1ms | 320 KiB | ||||
2 | Elfogadva | 1ms | 320 KiB | ||||
subtask2 | 16/16 | ||||||
3 | Elfogadva | 13ms | 1848 KiB | ||||
4 | Elfogadva | 10ms | 1848 KiB | ||||
5 | Elfogadva | 10ms | 1908 KiB | ||||
6 | Elfogadva | 12ms | 1848 KiB | ||||
7 | Elfogadva | 12ms | 1912 KiB | ||||
8 | Elfogadva | 12ms | 1864 KiB | ||||
subtask3 | 33/33 | ||||||
9 | Elfogadva | 16ms | 8248 KiB | ||||
10 | Elfogadva | 13ms | 8248 KiB | ||||
11 | Elfogadva | 14ms | 7480 KiB | ||||
12 | Elfogadva | 1ms | 320 KiB | ||||
13 | Elfogadva | 1ms | 320 KiB | ||||
14 | Elfogadva | 1ms | 320 KiB | ||||
15 | Elfogadva | 14ms | 8288 KiB | ||||
subtask4 | 0/51 | ||||||
16 | Futási hiba | 246ms | 262144 KiB | ||||
17 | Futási hiba | 206ms | 262144 KiB | ||||
18 | Futási hiba | 202ms | 262144 KiB | ||||
19 | Elfogadva | 23ms | 6696 KiB | ||||
20 | Elfogadva | 14ms | 2776 KiB | ||||
21 | Futási hiba | 252ms | 262144 KiB | ||||
22 | Futási hiba | 201ms | 262144 KiB | ||||
23 | Futási hiba | 204ms | 262144 KiB | ||||
24 | Futási hiba | 241ms | 262144 KiB |