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 <iostream>
#include <algorithm>
using namespace std;
int checkMatching(int** a, int** b, int n, int m, int r, int c, int sx, int sy);
int main() {
int n, m;
int r, c;
int **a, **b;
bool all_same = true;
int count = 0;
cin >> n >> m;
a = new int*[n];
for (int i = 0; i < n; i++) {
a[i] = new int[m];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
cin >> r >> c;
b = new int*[r];
for (int i = 0; i < r; i++) {
b[i] = new int[c];
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> b[i][j];
if (b[i][j] != b[0][0]) {
all_same = false;
}
}
}
if (all_same) {
cout << (n -r + 1) * (n - c + 1) << endl;
return 0;
}
for (int i = 0; i < n - r + 1; i++) {
for (int j = 0; j < m - c + 1; j++) {
if (checkMatching(a, b, n, m, r, c, i, j)) {
count++;
}
}
}
cout << count << endl;
for (int i = 0; i < n; i++) {
delete[] a[i];
}
for (int i = 0; i < r; i++) {
delete[] b[i];
}
delete[] a;
delete[] b;
return 0;
}
int checkMatching(int** a, int** b, int n, int m, int r, int c, int sx, int sy) {
long double p = 0;
int light_a1 = a[sx][sy];
bool flag = false;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (light_a1 != a[sx + i][sy + j]) {
int light_a2 = a[sx + i][sy + j];
p = (long double)(b[0][0] - b[i][j]) / (light_a1 - light_a2);
flag = true;
break;
}
}
if (flag) {
break;
}
}
long double q = b[0][0] - p * light_a1;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (p * a[sx + i][sy + j] + q - b[i][j] != 0) {
return 0;
}
}
}
return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |