728x90
programmers.co.kr/learn/courses/30/lessons/60059
#include <string>
#include <vector>
using namespace std;
bool checkAll(vector<vector<int>>totalArr, int m, int n){
for(int i=0;i<=n-1; i++){
for(int j=0; j<=n-1; j++){
if(totalArr[m-1+i][m-1+j]!=1){
return false;
}
}
}
return true;
}
bool putTogether(vector<vector<int>>totalArr,vector<vector<int>> key, int i , int j, int m, int n){
for(int a = 0; a<m; a++){
for(int b = 0; b<m; b++){
totalArr[i+a][j+b]+=key[a][b];
if(totalArr[i+a][j+b]>=2){return false;}
}
}
return checkAll(totalArr, m,n);
}
vector<vector<int>> clockwise(vector<vector<int>>key, int m){
vector<vector<int>>newKey(m,vector<int>(m));
for(int i=0; i<m; i++){
for(int j=0; j<m; j++){
newKey[i][j] = key[m-1-j][i];
}
}
return newKey;
}
bool solution(vector<vector<int>> key, vector<vector<int>> lock) {
bool answer = true;
int n,m;
n = lock.size();
m = key.size();
int k = 2*m-2+n;
vector<vector<int>>totalArr(k,vector<int>(k));
for(int i=0;i<=n-1; i++){
for(int j=0; j<=n-1; j++){
totalArr[m-1+i][m-1+j]= lock[i][j];
}
}
for(int t=0; t<4; t++){
for(int i=0; i<=m+n-2; i++){
for(int j=0; j<=m+n-2; j++){
if( putTogether(totalArr,key,i,j,m,n)==true)
{
return true;
}
}
}
key = clockwise(key,m);
}
return false;
}