이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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) {
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 = (double)(b[0][0] - b[i][j]) / (light_a1 - light_a2);
flag = true;
break;
}
}
if (flag) {
break;
}
}
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... |