알고리즘
백준 20365번 블로그2 C++
영춘권의달인
2023. 5. 29. 12:51
https://www.acmicpc.net/problem/20365
20365번: 블로그2
neighbor 블로그를 운영하는 일우는 매일 아침 풀고 싶은 문제를 미리 정해놓고 글을 올린다. 그리고 매일 밤 각각의 문제에 대하여, 해결한 경우 파란색, 해결하지 못한 경우 빨간색으로 칠한
www.acmicpc.net
B를 먼저 쭉 칠해놓은 경우와 R을 먼저 쭉 칠해놓은 경우를 비교해서 작은 값을 구한다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n;
string str;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
cin >> str;
int ans = n;
int ans1 = 1;
for (int i = 0; i < n;) {
if (str[i] == 'B') {
i++;
continue;
}
ans1++;
while (true) {
if (i >= n) break;
if (str[i] == 'B') break;
i++;
}
}
ans = min(ans, ans1);
int ans2 = 1;
for (int i = 0; i < n;) {
if (str[i] == 'R') {
i++;
continue;
}
ans2++;
while (true) {
if (i >= n) break;
if (str[i] == 'R') break;
i++;
}
}
ans = min(ans, ans2);
cout << ans;
}