답안 #231849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
231849 2020-05-15T05:08:08 Z kkr1221 흑백 이미지 찾기 (kriii3_G) C++14
0 / 101
410 ms 9464 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) {
    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;
}
# 결과 실행 시간 메모리 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 10 ms 512 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 410 ms 9464 KB Output isn't correct
2 Halted 0 ms 0 KB -