Submission #1316358

#TimeUsernameProblemLanguageResultExecution timeMemory
1316358djsksbrbfCount Squares (CEOI19_countsquares)C++20
100 / 100
1542 ms140920 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
#define fi first
#define se second
#define pb push_back
const int MOD = 1e9 + 7;
const int MAX = 2e5 + 5;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
#define int ll

signed main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   
   int h, w; cin >> h >> w;
   int a[h + 5], b[w + 5];
   for(int i = 1 ; i <= h ; i++)cin >> a[i];
   for(int i = 1 ; i <= w ; i++)cin >> b[i];
   map <int, int> mp;
   for(int i = 1 ; i <= h ; i++){
      for(int j = i + 1 ; j <= h ; j++){
         mp[a[j] - a[i]]++;
      }
   }
   
   ll ans = 0;
   for(int i = 1 ; i <= w ; i++){
      for(int j = i + 1 ; j <= w ; j++){
         ans += mp[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...