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

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

#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI = 6 * asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
static const int INF = 1 << 24;

template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
  v.assign(a, vector<T>(b, t));
}

// v.erase(unique(v.begin(),v.end()),v.end());

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    queue<int> q;
    rep(i, n) { q.push(i); }
    rep(i, m) {
      if (q.size() == 1) {
        reep(j, i, m) {
          string t;
          cin >> t;
        }
        break;
      }
      int fr = q.front();
      q.pop();
      string s;
      cin >> s;
      if ((i + 1) % 15 == 0) {
        if (s != "FizzBuzz") {

        } else {
          q.push(fr);
        }
      } else if ((i + 1) % 5 == 0) {
        if (s != "Buzz") {

        } else {
          q.push(fr);
        }
      } else if ((i + 1) % 3 == 0) {
        if (s != "Fizz") {

        } else {
          q.push(fr);
        }
      } else {
        stringstream ss;
        ss << s;
        int tt;
        ss >> tt;
        if (i + 1 == tt) {
          q.push(fr);
        } else {
        }
      }
    }
    vint v;
    while (!q.empty()) {
      v.PB(q.front());
      q.pop();
    }
    sort(ALL(v));
    rep(i, v.size()) {
      if (i)
        cout << " ";
      cout << v[i] + 1;
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

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

#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI = 6 * asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
static const int INF = 1 << 24;

template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
  v.assign(a, vector<T>(b, t));
}

// v.erase(unique(v.begin(),v.end()),v.end());

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    queue<int> q;
    rep(i, n) { q.push(i); }
    rep(i, m) {
      if (q.size() == 1)
        break;
      int fr = q.front();
      q.pop();
      string s;
      cin >> s;
      if ((i + 1) % 15 == 0) {
        if (s != "FizzBuzz") {

        } else {
          q.push(fr);
        }
      } else if ((i + 1) % 5 == 0) {
        if (s != "Buzz") {

        } else {
          q.push(fr);
        }
      } else if ((i + 1) % 3 == 0) {
        if (s != "Fizz") {

        } else {
          q.push(fr);
        }
      } else {
        stringstream ss;
        ss << s;
        int tt;
        ss >> tt;
        if (i + 1 == tt) {
          q.push(fr);
        } else {
        }
      }
    }
    vint v;
    while (!q.empty()) {
      v.PB(q.front());
      q.pop();
    }
    sort(ALL(v));
    rep(i, v.size()) {
      if (i)
        cout << " ";
      cout << v[i] + 1;
    }
    cout << endl;
  }
}