Untitled
#include <iostream> #include <array> #include <algorithm> int main() { using namespace std; unsigned N; cin >> N; string S; cin >> S; array<unsigned, 3> dp{}; auto&& [rock, scissors, paper]{dp}; for(const auto c : S){ // Moves are limited to those not equal to the previous one dp = {max(scissors, paper), max(rock, paper), max(rock, scissors)}; // Losing move must not be made = maximum winning count is 0 // Making winning move increases the maximum value +1 if (c == 'R') { scissors = 0; ++paper; } else if (c == 'S') { paper = 0; ++rock; } else if (c == 'P') { rock = 0; ++scissors; } } cout << ranges::max(dp) << endl; return 0; }
Leave a Comment