This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> pi;
int a[105][105], b[105][105];
int n, m, r, c;
bool ccw(pi a, pi b, pi c){
int dx1 = b.first - a.first;
int dy1 = b.second- a.second;
int dx2 = c.first - a.first;
int dy2 = c.second - a.second;
return 1ll * dx1 * dy2 != 1ll * dy1 * dx2;
}
vector<pi> v;
bool compare(int x, int y){
v.clear();
int mina = 1e9, minb = 1e9;
for(int i=1; i<=r; i++){
for(int j=1; j<=c; j++){
mina = min(mina, a[x+i-1][y+j-1]);
minb = min(minb, b[i][j]);
}
}
for(int i=1; i<=r; i++){
for(int j=1; j<=c; j++){
v.push_back(pi(a[x+i-1][y+j-1] - mina, b[i][j]- minb));
}
}
for(int i=0; i<(int)v.size() - 2; i++){
if(ccw(v[i],v[i+1],v[i+2]) == 0){
continue;
}
return 0;
}
return 1;
}
int main(){
scanf("%d %d",&n,&m);
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
scanf("%d",&a[i][j]);
}
}
scanf("%d %d",&r,&c);
for(int i=1; i<=r; i++){
for(int j=1; j<=c; j++){
scanf("%d",&b[i][j]);
}
}
int ret = 0;
for(int i=1; i<=n-r+1; i++){
for(int j=1; j<=m-c+1; j++){
if(compare(i,j)) ret++;
}
}
printf("%d",ret);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |