Language: C++

#include<bits/stdc++.h>
using namespace std;

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main(){
    string S;
    cin >> S;

    // 反転
    reverse(S.begin, S.end);
    for(int i=0; i<4; i++)
       reverse(divide[i].begin, divide[i].end);
    
    bool can = true;
    for(int i=0; i<S.size();i++){
        bool can2 = false;
        for(int j=0; j<4; j++){
            string d = divide[j];
            if(S.substr(i, d.size) == d){
                can2 = true;
                i += d.size();
            }
        }
        if(!can2){
            can = false;
            break;
        }
    }
    if(can){
        cout << "YES" <<endl;
    }else{
        cout << "NO" << endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:11:12: error: no matching function for call to 'reverse(<unresolved overloaded function type>, <unresolved overloaded function type>)'
   11 |     reverse(S.begin, S.end);
      |     ~~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:1083:5: note: candidate: 'template<class _BIter> void std::reverse(_BIter, _BIter)'
 1083 |     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
      |     ^~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1083:5: note:   template argument deduction/substitution failed:
a.cc:11:12: note:   couldn't deduce template parameter '_BIter'
   11 |     reverse(S.begin, S.end);
      |     ~~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:249:1: note: candidate: 'template<class _ExecutionPolicy, class _BidirectionalIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::reverse(_ExecutionPolicy&&, _BidirectionalIterator, _BidirectionalIterator)'
  249 | reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last);
      | ^~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:249:1: note:   candidate expects 3 arguments, 2 provided
a.cc:13:15: error: no matching function for call to 'reverse(<unresolved overloaded function type>, <unresolved overloaded function type>)'
   13 |        reverse(divide[i].begin, divide[i].end);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1083:5: note: candidate: 'template<class _BIter> void std::reverse(_BIter, _BIter)'
 1083 |     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
      |     ^~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1083:5: note:   template argument deduction/substitution failed:
a.cc:13:15: note:   couldn't deduce template parameter '_BIter'
   13 |        reverse(divide[i].begin, divide[i].end);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:249:1: note: candidate: 'template<class _ExecutionPolicy, class _BidirectionalIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::reverse(_ExecutionPolicy&&, _BidirectionalIterator, _BidirectionalIterator)'
  249 | reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last);
      | ^~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:249:1: note:   candidate expects 3 arguments, 2 provided
a.cc:20:30: error: invalid use of non-static member function 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]'
   20 |             if(S.substr(i, d.size) == d){
      |                            ~~^~~~
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/basic_string.h:1076:7: note: declared here
 1076 |       size() const _GLIBCXX_NOEXCEPT
      |       ^~~~