Submission #422794

#TimeUsernameProblemLanguageResultExecution timeMemory
422794Garguy22Count Squares (CEOI19_countsquares)C++17
100 / 100
2625 ms140860 KiB
//Count Squares
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int MAXN = 1507;

ll a[MAXN], b[MAXN];
map<ll, ll> m;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int h, v;
    cin >> h >> v;
    for(int i = 0; i < h; i++)
        cin >> a[i];
    for(int i = 0; i < v; i++)
        cin >> b[i];
    for(int i = 0; i < h; i++)
    {
        for(int j = i+1; j < h; j++)
            m[a[j]-a[i]]++;
    }
    ll ans = 0;
    for(int i = 0; i < v; i++)
    {
        for(int j = i+1; j < v; j++)
            ans += m[b[j]-b[i]];
    }
    cout << ans << endl;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...