Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- string coloredNecklace (string necklace) {
- char currentColor = necklace[0];
- int maxBeadCount = 0;
- for (int i = 0; i < necklace.size(); i++) {
- if (necklace[i] != currentColor && necklace[i] != 'w') {
- currentColor = necklace[i];
- }
- if (necklace[i] == 'w') {
- necklace[i] = currentColor;
- }
- }
- return necklace;
- }
- void maxBeadCount (string necklace, int &max) {
- int d = 1;
- for (int i = 0; i < necklace.size() - 1; i++) {
- while (i < necklace.size() && (necklace[i] == necklace[i + 1] || necklace[i] == 'w')) {
- d++;
- i++;
- }
- if (d > max) {
- max = d;
- }
- d = 1;
- }
- }
- int main () {
- freopen ("beads.in", "r", stdin);
- freopen ("beads.out", "w", stdout);
- int max = 0, n;
- string s;
- cin >> n >> s;
- s += s;
- maxBeadCount(coloredNecklace(s), max);
- reverse(s.begin(), s.end());
- maxBeadCount(coloredNecklace(s), max);
- if (max > n) {
- max /= 2;
- }
- cout << max << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment