프로그래머스
자물쇠와 열쇠 C++
by paysmile
2020. 11. 3.
#include <string>
#include <vector>
using namespace std;
vector<vector<int>> RotateKey(vector<vector<int>> key)
{
int size = key[0].size();
vector<vector<int>> temp(size,vector<int>(size));
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
temp[i][j] = key[size - j-1][i];
}
}
return temp;
}
bool solution(vector<vector<int>> key, vector<vector<int>> lock) {
bool answer = false;
int m = key[0].size();
int n = lock[0].size();
for (int k = 0; k < 4; k++) {
key = RotateKey(key);
for (int i = 0; i < n + (m - 1); i++) {
for (int j = 0; j < n + (m - 1); j++) {
vector<vector<int>> BigLock(n + (m - 1) * 2, vector<int>(n + (m - 1) * 2));
for (int ii = 0; ii < n; ii++) {
for (int jj = 0; jj < n; jj++) {
BigLock[ii + m - 1][jj + m - 1] = lock[ii][jj];
}
}
for (int ii = 0; ii < m; ii++) {
for (int jj = 0; jj < m; jj++) {
BigLock[i + ii][j + jj] += key[ii][jj];
}
}
int count = 0;
for (int ii = m - 1; ii < n + m - 1; ii++) {
for (int jj = m - 1; jj < n + m - 1; jj++) {
if (BigLock[ii][jj] == 1)
count++;
}
}
if (count == n*n) {
answer = true;
break;
}
}
}
}
return answer;
}