💻 문제 풀이 : C++
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int g_brown;
int g_yellow;
// 카펫 조건이 성립되면 True!!
int isCarpetOkay(int w, int h) {
if(w - 2 <=0 || h - 2 <= 0) return 0;
if(g_brown == w*h - (w-2)*(h-2))
return 1;
return 0;
}
// 공약수 조건을 따져가며 완전탐색!!
vector<int> getAns(int area) {
vector<int> result;
int width = area;
int height = 1;
while(width >= height) {
// 사각형이 성립되면(공약수)
if(area == width * height) {
// 카페트가 만들어지면
if(isCarpetOkay(width, height)){
// 정답!!
result.push_back(width);
result.push_back(height);
return result;
}
}
height++;
width = area / height;
}
}
vector<int> solution(int brown, int yellow) {
vector<int> answer;
// 변수 전역화
g_brown = brown;
// 답 벡터 복사
answer = getAns(brown+yellow);
return answer;
}