よじろめ覚書

私の理解度重視のソースコードです。

ABC054B - Template Matching

問題:B - Template Matching

#include <iostream>
#include <string>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)

string a[50], b[50];

bool isMatch(int n, int m, int y, int x) {
    if (m + y > n || m + x > n) {
        return false;
    }

    REP(i, m) {
        REP(j, m) {
            if (a[y + i][x + j] != b[i][j]) {
                return false;
            }
        }
    }

    return true;
}

int main(void) {
    int m, n;
    bool flg = false;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    REP(i, n) {
        cin >> a[i];
    }
    REP(i, m) {
        cin >> b[i];
    }

    REP(i, n - m + 1) {
        REP(j, n - m + 1) {
            if (isMatch(n, m, i, j)) {
                flg = true;
                break;
            }
        }

        if (flg) {
            break;
        }
    }

    cout << (flg? "Yes" : "No") << "\n";
    return 0;
}

a の位置を引数にしたにも関わらず使っていなくて、1WA。。