# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
231661 |
2020-05-14T09:52:03 Z |
kkr1221 |
흑백 이미지 찾기 (kriii3_G) |
C++14 |
|
417 ms |
9592 KB |
#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 |
1 |
Correct |
9 ms |
384 KB |
Output is correct |
2 |
Correct |
9 ms |
384 KB |
Output is correct |
3 |
Correct |
9 ms |
384 KB |
Output is correct |
4 |
Correct |
9 ms |
384 KB |
Output is correct |
5 |
Correct |
9 ms |
384 KB |
Output is correct |
6 |
Correct |
9 ms |
384 KB |
Output is correct |
7 |
Incorrect |
9 ms |
384 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
417 ms |
9592 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |