Submission #422907

#TimeUsernameProblemLanguageResultExecution timeMemory
422907Andyvanh1Count Squares (CEOI19_countsquares)C++14
100 / 100
2740 ms110272 KiB
#include <bits/stdc++.h> using namespace std; #define vt vector #define pb push_back #define all(x) (x).begin(),(x).end() #define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ ) typedef long long ll; typedef long double ld; typedef vt<int> vi; typedef pair<int,int> pii; map<int,int> mp1; map<int,int> mp2; void solve(){ int n, m; cin>>n>>m; vi arr1(n); vi arr2(m); rep(i,n)cin>>arr1[i]; rep(i,m)cin>>arr2[i]; vt<int> vec; for(int i = 0; i < n; i++){ for(int j = i+1; j < n; j++){ int x = arr1[j]-arr1[i]; if(mp1.find(x)==mp1.end()){ mp1[x] = 1; vec.pb(x); }else{ mp1[x]++; } } } for(int i = 0; i < m; i++){ for(int j = i+1; j < m; j++){ int x = arr2[j]-arr2[i]; if(mp2.find(x)==mp2.end()){ mp2[x] = 1; }else{ mp2[x]++; } } } ll ans = 0; for(auto& e: vec){ if(mp2.find(e)!=mp2.end()){ ans+= 1ll*mp2[e]*mp1[e]; } } cout<<ans<<'\n'; } int main(){ solve(); return 0; }

Compilation message (stderr)

countsquares.cpp: In function 'void solve()':
countsquares.cpp:8:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ )
      |                          ^
countsquares.cpp:24:5: note: in expansion of macro 'rep'
   24 |     rep(i,n)cin>>arr1[i];
      |     ^~~
countsquares.cpp:8:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ )
      |                          ^
countsquares.cpp:25:5: note: in expansion of macro 'rep'
   25 |     rep(i,m)cin>>arr2[i];
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...