완전탐색이라는 힌트가 있어서 쉽게 풀렸던 것 같다
(1,1)~(1,5000)까지의 카펫 사이즈를 완전탐색 해주었다.
한 개의 카펫사이즈에 대해 갈색 칸 수와 노랑색 칸 수를 구해서 답과 비교해야했는데 갈색을 가로 줄 한 줄*2+(세로-2)*2로 구하려니 작은 사각형은 적용하기 힘들었다.
노랑색 칸 수를 구하는 김에 사각형 넓이에서 빼버리면 되는 것을^^.. 조금 늦게 깨달았다.
(노랑색 구할 때 변의 길이가 음수가 되는 것에 유의하자!)
#include <string>
#include <vector>
#include<math.h>
using namespace std;
vector<int> solution(int brown, int yellow) {
vector<int> answer;
for(int i = 1;i<=5000;i++){
for(int j = 1;j<=i;j++){
int subi=max(0,i-2), subj =max(0,j-2);
int y = subi*subj;
int b = i*j-y;
if(b==brown&&y == yellow){
answer.push_back(i);
answer.push_back(j);
}
}
}
return answer;
}