123012024-12-11 17:59:32CsongiCsúcsokcpp17Futási hiba 49/100245ms262144 KiB
#include <bits/stdc++.h>
#define ll unsigned 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ÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva1ms508 KiB
2Elfogadva1ms320 KiB
subtask216/16
3Elfogadva12ms1848 KiB
4Elfogadva10ms1864 KiB
5Elfogadva9ms2004 KiB
6Elfogadva10ms2004 KiB
7Elfogadva10ms1848 KiB
8Elfogadva10ms1944 KiB
subtask333/33
9Elfogadva14ms8248 KiB
10Elfogadva13ms8428 KiB
11Elfogadva14ms7480 KiB
12Elfogadva1ms320 KiB
13Elfogadva1ms320 KiB
14Elfogadva1ms320 KiB
15Elfogadva14ms8184 KiB
subtask40/51
16Futási hiba202ms262144 KiB
17Futási hiba245ms262144 KiB
18Futási hiba243ms262144 KiB
19Elfogadva20ms6456 KiB
20Elfogadva13ms2788 KiB
21Futási hiba202ms262144 KiB
22Futási hiba207ms262144 KiB
23Futási hiba245ms262144 KiB
24Futási hiba243ms262144 KiB