문제 링크

요약

  • 쉬운문제

최종

  • 생각나는대로 풀면 된다. 어려울건 없음
#include <string>
#include <vector>
 
using namespace std;
 
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
 
vector<int> solution(int brown, int yellow) {
	for (int w = 3; ; w++) {
		int h = brown / 2 + 2 - w;
 
		if (yellow == (w - 2) * (h - 2)) {
			return {MAX(w, h), MIN(w, h)};
		}
	}
 
	// Should not happen
	return {0, 0};
}
  • 다만 실수한건
    • 그냥 무지성으로 w, h 모두 무한 for 에 넣어서 이중 for 문으로 돌렸더니 timeout 난다.
    • 당연한건데, outer loop 가 고정된 상태에서 inner loop 에 정답을 못찾아 무한 loop 가 걸리는 것
    • 이거때문에 한 5분 버렸다.