답안 #15286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
15286 2015-07-12T05:20:59 Z myungwoo 흑백 이미지 찾기 (kriii3_G) C++14
0 / 101
3 ms 16708 KB
#pragma warning(disable:4996)

#include <stdio.h>
#include <algorithm>
using std::swap;

int n, m, r, c;
long long a[1000][1000];
long long b[1000][1000];

double s;
bool zero(double v)
{
	double eps = s * 1e-6;
	return -eps <= v && v <= eps;
}

int rk(double m[][3])
{
	int n = 3;
	int r = 0;

	for (int i=0; i<n; i++)
		for (int j=0; j<n; j++)
			if (s < m[i][j])
				s = m[i][j];

	for (int i=0; i<n; i++) {
		bool f = false;
		for (int j=r; j<n; j++) {
			if (!zero(m[j][i])) {
				f = true;
				for (int k=0; k<n; k++)
					swap(m[r][k], m[j][k]);
				break;
			}
		}

		if (f) {
			for (int j=r+1; j<n; j++) {
				double mul = m[j][i] / m[r][i];
				for (int k=0; k<n; k++)
					m[j][k] -= mul * m[r][k];
			}
			r++;
		}
	}

	return r;
}

int rk(double m11, double m12, double m13, double m22, double m23, double m33)
{
	double m21 = m12;
	double m31 = m13;
	double m32 = m23;

	double m[3][3] = {m11, m12, m13, m21, m22, m23, m31, m32, m33};

	return rk(m);
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i=0; i<n; i++) for (int j=0; j<m; j++) scanf("%lld", &a[i][j]);
	scanf("%d%d", &r, &c);
	for (int i=0; i<r; i++) for (int j=0; j<c; j++) scanf("%lld", &b[i][j]);

	int ans = 0;
	for (int i=0; i<=n-r; i++) {
		for (int j=0; j<=m-c; j++) {
			long long ass = 0, bss = 0, as = 0, bs = 0, abs = 0, os = 0;
			for (int k=0; k<r; k++) {
				for (int l=0; l<c; l++) {
					ass += a[i+k][j+l] * a[i+k][j+l];
					abs += a[i+k][j+l] * b[k][l];
					bss += b[k][l] * b[k][l];
					as += a[i+k][j+l];
					bs += b[k][l];
					os++;
				}
			}

			if (rk(ass, as, -abs, os, -bs, bss) <= 2)
				ans++;
		}
	}

	printf("%d\n", ans);

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16708 KB Output is correct
2 Incorrect 0 ms 16708 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Halted 0 ms 0 KB -