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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-2;
const int inf = 1e8;
#define MOD 1000000007
// a^b mod MOD
ll powmod(ll a, ll b) {
  ll out = 1;
  ll p = a % MOD;
  while (b) {
    if (b & 1)
      out = out * p % MOD;
    p = p * p % MOD;
    b >>= 1;
  }
  return out;
}
// nCr
vector<ll> d;
ll nCr(ll n, ll r) {
  ll out = 1;
  r = min(r, n - r);
  if (r < 0)
    return 0;
  for (ll i = n; i > n - r; i--)
    out = out * (i % MOD) % MOD;
  ll t = d[r]; // 1;
  //	for(ll i=2;i<=r;i++)t=t*i%MOD;
  return out * powmod(t, MOD - 2) % MOD;
}
int main() {
  d = vector<ll>(210000);
  d[0] = d[1] = 1;
  for (ll i = 2; i < 210000; i++)
    d[i] = d[i - 1] * i % MOD;
  ll n, m, x;
  cin >> n >> m >> x;
  ll out = 0;
  for (ll i = 0; i < x + 1; i++) {
    ll t = 1;
    (t *= (nCr(n + 2 * i, i) - nCr(n + 2 * i, i - 1) + MOD) % MOD) %= MOD;
    (t *=
     (nCr(m + 2 * (x - i), x - i) - nCr(m + 2 * (x - i), x - i - 1) + MOD) %
     MOD) %= MOD;
    (t *= nCr(n + m + 2 * x, n + 2 * i)) %= MOD;
    (out += t) %= MOD;
  }
  cout << out << endl;
}
/*
int main(){
        int d[]={0,1,1,0};//kyosi
        vvd w(2,vd(4,0.5));//weight
        int x[]={1,2};//input
        int cnt=10000;
        while(cnt--){
                vd y(4);
                rep(i,4)rep(j,2)y[i]+=w[j][i]*x[j];
                double E=0;
                rep(i,4)E-=(d[i]*log(y[i])+(1-d[i])*log(1-y[i]));
                //BP
                rep(i,2)rep(j,4)w[i][j]-=EPS*(y[j]-d[j])*x[i]*(exp(-y[j])/pow(1+exp(-y[j]),2));

//		cout<<cnt<<endl;
//		rep(i,2){rep(j,4)cout<<" "<<shosu(9)<<w[i][j];cout<<endl;}
//		cout<<endl;
        }
        rep(i,2){rep(j,4)cout<<" "<<shosu(9)<<w[i][j];cout<<endl;}
        cout<<endl;
        rep(i,4)cout<<" "<<shosu(9)<<w[0][i]*x[0]+w[1][i]*x[1];
        cout<<endl;
}
//*/

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-2;
const int inf = 1e8;
#define MOD 1000000007
// a^b mod MOD
ll powmod(ll a, ll b) {
  ll out = 1;
  ll p = a % MOD;
  while (b) {
    if (b & 1)
      out = out * p % MOD;
    p = p * p % MOD;
    b >>= 1;
  }
  return out;
}
// nCr
ll nCr(ll n, ll r) {
  ll out = 1;
  r = min(r, n - r);
  if (r < 0)
    return 0;
  for (ll i = n; i > n - r; i--)
    out = out * (i % MOD) % MOD;
  ll t = 1;
  for (ll i = 2; i <= r; i++)
    t = t * i % MOD;
  return out * powmod(t, MOD - 2) % MOD;
}
int main() {
  ll n, m, x;
  cin >> n >> m >> x;
  ll out = 0;
  for (ll i = 0; i < x + 1; i++) {
    ll t = 1;
    (t *= (nCr(n + 2 * i, i) - nCr(n + 2 * i, i - 1) + MOD) % MOD) %= MOD;
    (t *=
     (nCr(m + 2 * (x - i), x - i) - nCr(m + 2 * (x - i), x - i - 1) + MOD) %
     MOD) %= MOD;
    (t *= nCr(n + m + 2 * x, n + 2 * i)) %= MOD;
    (out += t) %= MOD;
  }
  cout << out << endl;
}
/*
int main(){
        int d[]={0,1,1,0};//kyosi
        vvd w(2,vd(4,0.5));//weight
        int x[]={1,2};//input
        int cnt=10000;
        while(cnt--){
                vd y(4);
                rep(i,4)rep(j,2)y[i]+=w[j][i]*x[j];
                double E=0;
                rep(i,4)E-=(d[i]*log(y[i])+(1-d[i])*log(1-y[i]));
                //BP
                rep(i,2)rep(j,4)w[i][j]-=EPS*(y[j]-d[j])*x[i]*(exp(-y[j])/pow(1+exp(-y[j]),2));

//		cout<<cnt<<endl;
//		rep(i,2){rep(j,4)cout<<" "<<shosu(9)<<w[i][j];cout<<endl;}
//		cout<<endl;
        }
        rep(i,2){rep(j,4)cout<<" "<<shosu(9)<<w[i][j];cout<<endl;}
        cout<<endl;
        rep(i,4)cout<<" "<<shosu(9)<<w[0][i]*x[0]+w[1][i]*x[1];
        cout<<endl;
}
//*/