/* -*- coding: utf-8 -*- * * 1924.cc: No.1924 3 color painting on a line - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ /* global variables */ char s[MAX_N + 4]; /* subroutines */ /* main */ int main() { int n; scanf("%d%s", &n, s); int m = 0; for (int i = 0; i < n;) { int j = i; while (i < n && s[j] == s[i]) i++; s[m++] = s[j]; } s[m] = '\0'; n = m; //puts(s); int c = 0; m = 0; for (int i = 0; i < n; i++) { if (m >= 2 && s[m - 2] == s[i]) m -= 2, c++; s[m++] = s[i]; } s[m] = '\0'; n = m; //printf("%s, c=%d\n", s, c); for (int i = 0; i < n; i++) if (i % 3 != 0) s[i] = '\0', c++; //printf("%s, c=%d\n", s, c); printf("%d\n", c + 1); return 0; }