Problem p00768 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#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 <utility>
#include <vector>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

#define dump(x) cerr << #x << " = " << (x) << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define sz size()

class TEAM {
public:
  int pena[20];
  int sum;
  int time;
  int num;
  int point;

  TEAM() {
    rep(i, 20) pena[i] = 0;
    sum = time = num = point = 0;
  }
};

int main() {
  int M, T, P, R;
  while (cin >> M >> T >> P >> R) {
    TEAM team[100];

    if (M == 0 && T == 0 && P == 0 && R == 0)
      break;

    rep(i, T) team[i].num = i + 1;

    rep(i, R) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--;
      if (j == 0) {
        team[t].sum++;
        team[t].time += m + team[t].pena[p] * 20;
      } else {
        team[t].pena[p]++;
      }
    }

    rep(i, T) {
      team[i].point = team[i].sum * 100000000 + 10000000 - team[i].time;
    }

    for (int i = 0; i < T - 1; i++) {
      for (int j = T - 1; j > i; j--) {
        if (team[j].point < team[j - 1].point)
          swap(team[j], team[j - 1]);
      }
    }

    cout << team[T - 1].num;
    //        cout<<" "<<team[T-1].point<<endl;
    for (int i = T - 2; i >= 0; i--) {
      if (team[i + 1].point == team[i].point) {
        cout << "=" << team[i].num;
        //                cout<<" "<<team[i].point<<endl;
      } else {
        cout << "," << team[i].num;
        //                cout<<" "<<team[i].point<<endl;
      }
    }
    cout << endl;
  }
  return 0;
}

/*
int main(){
    int M,T,P,R;
    while(cin>>M>>T>>P>>R){
        TEAM team[100];


        if(M==0 && T==0 && P==0 && R==0)break;

        rep(i,T)team[i].num=i;

        rep(i,R){
            int m,t,p,j;
            cin>>m>>t>>p>>j;
            t--;
            if(j==0){
                team[t].sum++;
                team[t].time+=m+team[t].pena[p]*20;
            }else{
                team[t].pena[p]++;
            }
        }

        rep(i,T){
            team[i].point=team[i].sum*100000000 + 10000000-team[i].time;
        }

        for(int i=T-1;i>=1;i--){
            for(int j=i;j>=1;j--){
                if(team[j].point>team[j-1].point)swap(team[j],team[j-1]);
            }
        }
        cout<<team[T-1].num+1;
        cout<<" "<<team[T-1].point<<endl;
        for(int i=T-2;i>=0;i--){
            if(team[i-1].point==team[i].point){
                cout<<"="<<team[i].num+1;
                cout<<" "<<team[i].point<<endl;
            }
            else{
                cout<<","<<team[i].num+1;
                cout<<" "<<team[i].point<<endl;
            }
        }
        cout<<endl;
    }

    return 0;
}
 */

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define INF 1e9

typedef long long int ll;
using namespace std;

int wacount[51][11] = {};
int timesum[11] = {}, anssum[11];

bool checkOver(int a, int b) {
  if (anssum[a] < anssum[b])
    return true;
  if ((anssum[a] == anssum[b]) && (timesum[a] > timesum[b]))
    return true;
  return false;
}

void babu_sort(int anssum[11], int timesum[11], int grad[11], int T) {
  for (int i = 0; i < T; i++) {
    for (int j = 0; j < T - 1 - i; j++) {
      if (checkOver(grad[j], grad[j + 1])) {
        swap(grad[j], grad[j + 1]);
      }
    }
  }
}

void out(int timesum[11], int grad[11], int T) {
  vector<char> ans;

  ans.push_back(grad[0] + '0');
  for (int i = 1; i < T; i++) {
    if (anssum[grad[i]] == anssum[grad[i - 1]] &&
        timesum[grad[i]] == timesum[grad[i - 1]]) {
      ans.push_back('=');

      if (grad[i] < 10) {
        ans.push_back(grad[i] + '0');
      } else {
        ans.push_back(grad[i] / 10 + '0');
        ans.push_back(grad[i] % 10 + '0');
      }
    } else {
      ans.push_back(',');

      if (grad[i] < 10) {
        ans.push_back(grad[i] + '0');
      } else {
        ans.push_back(grad[i] / 10 + '0');
        ans.push_back(grad[i] % 10 + '0');
      }
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i];
  }
  cout << endl;
}

void solve(int anssum[11], int timesum[11], int M, int T, int P, int R) {
  int grad[11];
  for (int i = T; i >= 1; i--) {
    grad[T - i] = i;
  }
  babu_sort(anssum, timesum, grad, T);
  out(timesum, grad, T);
}

/*
int wacount[51][11]={};
int timesum[11]={},anssum[11];

*/

int main() {
  while (1) {

    for (int i = 0; i < 11; i++) {
      for (int j = 0; j < 51; j++) {
        wacount[j][i] = 0;
      }
      timesum[i] = 0;
      anssum[i] = 0;
    }

    int M, T, P, R;
    int m, t, p, J;
    cin >> M >> T >> P >> R;
    if (M == 0 && T == 0 && P == 0 && R == 0)
      break;
    for (int i = 0; i < R; i++) {
      cin >> m >> t >> p >> J;
      if (J != 0) {
        wacount[t][p]++;
      } else {
        timesum[t] += m + wacount[t][p] * 20;
        anssum[t]++;
      }
    }
    solve(anssum, timesum, M, T, P, R);
  }
  return 0;
}