Problem p03854 (C++)

Buggy submission (status: Time Limit Exceeded):
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
inline long long toint(string s) {
  long long v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef long long ll;
typedef long long LL;
typedef vector<int> vi;
typedef vector<long long> VLL;
typedef vector<long long> vll;
typedef vector<string> ves;
typedef vector<char> vech;

typedef pair<long long, long long> pll;
typedef pair<long long, long long> PLL;
typedef map<ll, ll> mll;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<char, ll> mcl;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define VECMAX(x) *max_element(ALL(x))
#define VECMIN(x) *min_element(ALL(x))
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// #define MULTIPLE(i,n,k) for(int i = (k) ; i<(n) ; i+=k+1)//倍数ループ
// constant
//------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
#define SIZEOF(x) sizeof(x) / sizeof(x[0])

const long long INF = 100000000000000;
const long long NINF = -100000000000000;

//-------------------------------------------------------------

//-----------MAIN------------//
// 注意::::DPの配列、vectorはグローバル変数を使え！！そして引数として与えるな！！
//       Sqrは２乗 sqrtはルート
#define CIN(a) REP(i, a.size()) cin >> a[i];

int main() {
  string s;
  cin >> s;
  string t = "";
  map<string, bool> p;
  p["esare"] = true;
  p["resare"] = true;
  p["maerd"] = true;
  p["remaerd"] = true;
  ll v = s.size();
  REP(i, v) {
    int ind = v - i - 1;
    t += s[ind];
    if (p[t]) {
      t = "";
    }
  }
  if (!t.size())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


Fixed submission:
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
inline long long toint(string s) {
  long long v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef long long ll;
typedef long long LL;
typedef vector<int> vi;
typedef vector<long long> VLL;
typedef vector<long long> vll;
typedef vector<string> ves;
typedef vector<char> vech;

typedef pair<long long, long long> pll;
typedef pair<long long, long long> PLL;
typedef map<ll, ll> mll;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<char, ll> mcl;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define VECMAX(x) *max_element(ALL(x))
#define VECMIN(x) *min_element(ALL(x))
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// #define MULTIPLE(i,n,k) for(int i = (k) ; i<(n) ; i+=k+1)//倍数ループ
// constant
//------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
#define SIZEOF(x) sizeof(x) / sizeof(x[0])

const long long INF = 100000000000000;
const long long NINF = -100000000000000;

//-------------------------------------------------------------

//-----------MAIN------------//
// 注意::::DPの配列、vectorはグローバル変数を使え！！そして引数として与えるな！！
//       Sqrは２乗 sqrtはルート
#define CIN(a) REP(i, a.size()) cin >> a[i];

int main() {
  string s;
  cin >> s;
  string t = "";
  map<string, bool> p;
  p["esare"] = true;
  p["resare"] = true;
  p["maerd"] = true;
  p["remaerd"] = true;
  ll v = s.size();
  REP(i, v) {
    int ind = v - i - 1;
    t += s[ind];
    if (p[t]) {
      t = "";
    }
    if (t.size() > 10) {
      break;
    }
  }
  if (!t.size())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}