Problem p01307 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define RPA(i, s, e) for (int i = s; i <= e; i++)
#define RPD(i, s, e) for (int i = s; i >= e; i--)
#define PB(a) push_back(a)
#define MP(i, s) make_pair(i, s)
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(), (a).end()
#define PRT(a) cout << (a) << endl
#define PRT2(a, b) cout << (a) << " " << (b) << endl
#define PRT3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl

typedef vector<int> VI;
typedef long long LL;
typedef pair<int, int> P;

int isWin(vector<int> num, int played) {
  if (num.size() == 1)
    return false;
  bool res = false;
  vector<int> next = num;
  int a = next.back();
  next.pop_back();
  int b = next.back();
  next.pop_back();
  if (a + b >= 10) {
    next.push_back(1);
    next.push_back((a + b) % 10);
  } else {
    next.push_back(a + b);
  }
  if (!isWin(next, played + 1))
    res = true;

  return res;
}

void coding() {
  int n;
  string num;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> num;
    vector<int> v;
    for (int k = 0; k < num.size(); k++) {
      v.push_back(num[k] - '0');
    }
    if (isWin(v, 0)) {
      printf("Fabre wins.\\n");
    } else {
      printf("Audrey wins.\\n");
    }
  }
}

// #define _LOCAL_TEST

int main() {
#ifdef _LOCAL_TEST
  clock_t startTime = clock();
  freopen("a.in", "r", stdin);
#endif

  coding();

#ifdef _LOCAL_TEST
  clock_t elapsedTime = clock() - startTime;
  cout << endl;
  cout << (elapsedTime / 1000.0) << " sec elapsed." << endl;
  cout << "This is local test" << endl;
  cout << "Do not forget to comment out _LOCAL_TEST" << endl << endl;
#endif
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define RPA(i, s, e) for (int i = s; i <= e; i++)
#define RPD(i, s, e) for (int i = s; i >= e; i--)
#define PB(a) push_back(a)
#define MP(i, s) make_pair(i, s)
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(), (a).end()
#define PRT(a) cout << (a) << endl
#define PRT2(a, b) cout << (a) << " " << (b) << endl
#define PRT3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl

typedef vector<int> VI;
typedef long long LL;
typedef pair<int, int> P;

bool isWin(string num) {
  if (num.size() == 1)
    return false;
  bool res = false;
  for (int i = 0; i < num.size() - 1; i++) {
    int a = num[i] - '0';
    int b = num[i + 1] - '0';
    string next = num;
    if (a + b >= 10) {
      next[i] = '1';
      next[i + 1] = '0' + ((a + b) % 10);
    } else {
      next = num.substr(0, i) + " " + num.substr(i + 2);
      next[i] = '0' + (a + b);
    }
    if (!isWin(next))
      res = true;
  }
  return res;
}

void coding() {
  int n;
  string num;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> num;
    if (isWin(num)) {
      printf("Fabre wins.\\n");
    } else {
      printf("Audrey wins.\\n");
    }
  }
}

// #define _LOCAL_TEST

int main() {
#ifdef _LOCAL_TEST
  clock_t startTime = clock();
  freopen("a.in", "r", stdin);
#endif

  coding();

#ifdef _LOCAL_TEST
  clock_t elapsedTime = clock() - startTime;
  cout << endl;
  cout << (elapsedTime / 1000.0) << " sec elapsed." << endl;
  cout << "This is local test" << endl;
  cout << "Do not forget to comment out _LOCAL_TEST" << endl << endl;
#endif
}