Language: C++

#include <iostream>
#include <vector>

std::vector<char>::const_iterator CheckStones(const std::vector<char> &stones, int firstWhiteIndex)
{
    if (firstWhiteIndex >= stones.size())
    {   // 白石が無いので、OK
        return stones.end();
    }

    // 白石より後に赤石があるとダメ
    return std::find(stones.begin() + firstWhiteIndex + 1, stones.end(), 'R');
}

int FindStone(const std::vector<char>& stones, char color, int offset)
{
    for (auto index = offset; index < stones.size(); ++index)
    {
        if (stones[index] == color)
        {
            return index;
        }
    }

    return stones.size();
}

int FindRed(const std::vector<char>& stones, int offset, int firstWhiteIndex)
{
    for (auto index = offset; index > firstWhiteIndex; --index)
    {
        if (stones[index] == 'R')
        {
            return index;
        }
    }

    return stones.size();
}

int main()
{
    int n;
    std::cin >> n;
    std::vector<char> stones(n);

    int firstWhiteIndex = n;
    for (auto index = 0; index < n; ++index)
    {
        std::cin >> stones[index];
        if (index < firstWhiteIndex && stones[index] == 'W')
        {
            firstWhiteIndex = index;
        }
    }

    int lastRedIndex = FindRed(stones, stones.size() - 1, firstWhiteIndex);
    size_t count = 0;
    while (true)
    {
        auto redPos = CheckStones(stones, firstWhiteIndex);
        if (redPos == stones.end())
        {
            break;
        }
        // 交換できるなら交換が早い、交換すべき物がないなら色変え
        stones[firstWhiteIndex] = 'R';
        if (lastRedIndex < n)
        {
            stones[lastRedIndex] = 'W';
            lastRedIndex = FindRed(stones, lastRedIndex - 1, firstWhiteIndex);
        }

        firstWhiteIndex = FindStone(stones, 'W', firstWhiteIndex + 1);

        ++count;
    }
    
    std::cout << count;
}

Compiler output:
a.cc: In function 'std::vector<char>::const_iterator CheckStones(const std::vector<char>&, int)':
a.cc:12:21: error: no matching function for call to 'find(__gnu_cxx::__normal_iterator<const char*, std::vector<char> >, std::vector<char>::const_iterator, char)'
   12 |     return std::find(stones.begin() + firstWhiteIndex + 1, stones.end(), 'R');
      |            ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:12:21: note:   '__gnu_cxx::__normal_iterator<const char*, std::vector<char> >' is not derived from 'std::istreambuf_iterator<_CharT>'
   12 |     return std::find(stones.begin() + firstWhiteIndex + 1, stones.end(), 'R');
      |            ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~