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

// kZime
#include <bits/stdc++.h>

#define ONLINE_JUDGE

using namespace std;
#ifndef ONLINE_JUDGE
#define wi(x) cerr << #x << ": " << (x) << '\\n';
#else
#define wi(x)
#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
template <typename T> inline T getNum() {
  T k = 0;
  int c = getchar(), f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    k = k * 10 + c - '0';
  return k * f;
}
#define gn() getNum<int>()
#define gl() getNum<ll>()
clock_t opt, edt;
inline void init() {
#ifndef ONLINE_JUDGE
  freopen("../input.txt", "r", stdin);
  //    freopen("../input.txt", "w", stdout);
  opt = clock();
#endif
}

inline void tini() {
#ifndef ONLINE_JUDGE
  edt = clock();
  cerr << "\\n#cost: " << (double)(edt - opt) / CLOCKS_PER_SEC << "s\\n";
#endif
}

int main() {
  init();
  ///////////////////////////////////////////////////////////////////////////////

  int a = gn(), b = gn();
  cout << (a * (a - 1)) / 2 + (b * (b - 1)) / 2;

  ///////////////////////////////////////////////////////////////////////////////
  tini();
}

/*
char Ma[MAXN*2];
int Mp[MAXN*2];
void Manacher(char s[],int len){
    int l=0;
    Ma[l++]='$';
    Ma[l++]='#';
    for(int i=0;i<len;i++){
        Ma[l++]=s[i];
        Ma[l++]='#';
    }
    Ma[l]=0;
    int mx=0,id=0;
    for(int i=0;i<l;i++){
        Mp[i]=mx>i?min(Mp[2*id−i],mx−i):1;
        while(Ma[i+Mp[i]]==Ma[i−Mp[i]])Mp[i]++;
        if(i+Mp[i]>mx){
            mx=i+Mp[i];
            id=i;
        }
    }
}
*/
/*
 * * abaaba
 * * i:     0 1 2 3 4 5 6 7 8 9 10 11 12 13
 * * Ma[i]: $ # a # b # a # a # b  #  a  #
 * * Mp[i]: 1 1 2 1 4 1 2 7 2 1 4  1  2  1
 */
/*
char s[MAXN];
int main(){
   while(scanf("%s",s)==1){
       int len=strlen(s);
       Manacher(s,len);
       int ans=0;
       for(int i=0;i<2*len+2;i++)
           ans=max(ans,Mp[i]−1);
       printf("%d\\n",ans);
   }
   return 0;
}
*/

Error: TLE

Fixed submission:

// kZime
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define wi(x) cerr << #x << ": " << (x) << '\\n';
#else
#define wi(x)
#endif
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
template <typename T> inline T getNum() {
  T k = 0;
  int c = getchar(), f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    k = k * 10 + c - '0';
  return k * f;
}
#define gn() getNum<int>()
#define gl() getNum<ll>()
clock_t opt, edt;
inline void init() {
#ifndef ONLINE_JUDGE
  freopen("../input.txt", "r", stdin);
  //    freopen("../input.txt", "w", stdout);
  opt = clock();
#endif
}

inline void tini() {
#ifndef ONLINE_JUDGE
  edt = clock();
  cerr << "\\n#cost: " << (double)(edt - opt) / CLOCKS_PER_SEC << "s\\n";
#endif
}

int main() {
  init();
  ///////////////////////////////////////////////////////////////////////////////

  int a = gn(), b = gn();
  cout << (a * (a - 1)) / 2 + (b * (b - 1)) / 2;

  ///////////////////////////////////////////////////////////////////////////////
  tini();
}

/*
char Ma[MAXN*2];
int Mp[MAXN*2];
void Manacher(char s[],int len){
    int l=0;
    Ma[l++]='$';
    Ma[l++]='#';
    for(int i=0;i<len;i++){
        Ma[l++]=s[i];
        Ma[l++]='#';
    }
    Ma[l]=0;
    int mx=0,id=0;
    for(int i=0;i<l;i++){
        Mp[i]=mx>i?min(Mp[2*id−i],mx−i):1;
        while(Ma[i+Mp[i]]==Ma[i−Mp[i]])Mp[i]++;
        if(i+Mp[i]>mx){
            mx=i+Mp[i];
            id=i;
        }
    }
}
*/
/*
 * * abaaba
 * * i:     0 1 2 3 4 5 6 7 8 9 10 11 12 13
 * * Ma[i]: $ # a # b # a # a # b  #  a  #
 * * Mp[i]: 1 1 2 1 4 1 2 7 2 1 4  1  2  1
 */
/*
char s[MAXN];
int main(){
   while(scanf("%s",s)==1){
       int len=strlen(s);
       Manacher(s,len);
       int ans=0;
       for(int i=0;i<2*len+2;i++)
           ans=max(ans,Mp[i]−1);
       printf("%d\\n",ans);
   }
   return 0;
}
*/