Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions 17주차/(P)60059/60059_cpp_jy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <vector>
using namespace std;

int N,M;
vector<vector<int>> map;

// 잠금이 해제되어있는지
bool check(vector<vector<int>>& key, int y, int x){
bool ret = true;

for(int i=y;i<y+M;i++)
for(int j=x;j<x+M;j++)
map[i][j]+=key[i-y][j-x];

for(int i=M;i<M+N;i++){
for(int j=M;j<M+N;j++){
if(map[i][j]!=1){
ret=false;
break;
}
}
if(!ret) break;
}

for(int i=y;i<y+M;i++)
for(int j=x;j<x+M;j++)
map[i][j]-=key[i-y][j-x];

return ret;
}

bool solution(vector<vector<int>> key, vector<vector<int>> lock) {
bool answer = false;

M = key.size();
N = lock.size();

map = vector<vector<int>>(2*M+N,vector<int>(2*M+N));

// 보드에 입력하기
for(int i=M;i<M+N;i++)
for(int j=M;j<M+N;j++)
map[i][j]=lock[i-M][j-M];

// 상하좌우
for(int i=0;i<N+M;i++){
for(int j=0;j<N+M;j++){
for(int k=0;k<4;k++){
vector<vector<int>> tmp(M,vector<int>(M));
for(int i=0;i<M;i++)
for(int j=0;j<M;j++)
tmp[i][j] = key[j][M-i-1];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5중 for 문이네요.. ㄷㄷ


for(int i=0;i<M;i++)
for(int j=0;j<M;j++)
key[i][j] = tmp[i][j];

if(check(key,i,j)){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

깔끔한 함수 사용입니다

answer = true;
break;
}
}
if(answer) break;
}
if(answer) break;
}

return answer;
}