사용 언어 : c++
<풀이>
행이랑 열이 왜이리 헷갈리던지 ..ㅠ
열을 기준으로 행을 1단씩 뛰어가면서 'O' 체크가 되어있는 부분이 최대로 카운트되는 곳을 찾아낸 후 'X'가 나온 그 행부터 다시 같은 수행을 반복하면 풀리는 문제
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int total_period = 0, room = 0; //여름 성수기 총 기간, 방 개수
int checkIn = 0, checkOut = 0;
char temp[101][31];
int greedy(int index) {
int maxCount = 0;
for (int i = 0; i < room; i++) {
int count = 0;
for (int j = index; j < checkOut - 1; j++) {
if (temp[j][i] == 'O') { count++; }
else { break; }
}
if (maxCount < count) {
maxCount = count;
}
}
return maxCount;
}
int main() {
cin >> total_period >> room;
for (int i = 0; i < total_period; i++) {
for (int j = 0; j < room; j++) {
cin >> temp[i][j];
}
}
cin >> checkIn >> checkOut;
int change = -1;
for (int i = checkIn - 1; i < checkOut - 1;) {
change++;
if (greedy(i) == 0) {
change = -1;
break;
}
i += greedy(i);
}
cout << change << endl;;
}