提出 #1105535


ソースコード 拡げる

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

int main() {
	
	// input
	int n, m;
	cin >> n >> m;
	
	string image [n];
	string templ [m];
	
	for (int i = 0; i < n; i++) {
		cin >> image[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> templ[i];
	}
	
	bool found = false;
	
	// horizontal
	for (int i = 0; i <= n-m; i++) {
		// vertical
		for (int j = 0; j <= n-m; j++) {
			// substring match
			if (image[i].substr(j,m) == templ[0]) {
				if (m == 1) found = true;
				// check the lines below
				for (int k = 1; k < m; k++) {
					if (image[i+k].substr(j,m) != templ[k]) break;
					if (k == m - 1) found = true;
				}
			}
			// no match - continue
		}
	}
	
	if (found) cout << "Yes";
	else cout << "No";
	return 0;
}

提出情報

提出日時
問題 B - Template Matching
ユーザ tom_mol
言語 C++14 (GCC 5.4.1)
得点 200
コード長 775 Byte
結果 AC
実行時間 1 ms
メモリ 256 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 200 / 200
結果
AC × 2
AC × 10
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All sample_01.txt, sample_02.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt
ケース名 結果 実行時間 メモリ
sample_01.txt AC 1 ms 256 KiB
sample_02.txt AC 1 ms 256 KiB
subtask_1_01.txt AC 1 ms 256 KiB
subtask_1_02.txt AC 1 ms 256 KiB
subtask_1_03.txt AC 1 ms 256 KiB
subtask_1_04.txt AC 1 ms 256 KiB
subtask_1_05.txt AC 1 ms 256 KiB
subtask_1_06.txt AC 1 ms 256 KiB
subtask_1_07.txt AC 1 ms 256 KiB
subtask_1_08.txt AC 1 ms 256 KiB