alexjercan/bugnet huggingface dataset:
Problem p00864 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::list;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set; // insert erase find count
using std::setprecision;
using std::stack;
using std::string;
using std::vector;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int>> PIII;

int main(void) {
  while (1) {
    int n;
    int w;
    cin >> n >> w;
    if (n == 0 && w == 0) {
      break;
    }

    int sep = (100 / w) + 1;
    // std::cerr << "SEP = " << sep << endl;
    Vec<int> hist(sep, 0);

    int n_max = 0;
    int number;
    for (int i = 0; i < n; i++) {
      cin >> number;
      n_max = max(n_max, number);
      hist[number / w]++;
    }

    int h_max = 0;
    for (int i = 0; i < (int)hist.size(); i++) {
      h_max = max(h_max, hist[i]);
    }

    int w_num = n_max / w;
    // std::cerr << w_num << endl;

    int mom = 0;
    int chi = w_num * h_max;

    for (int i = 0; i < (int)hist.size(); i++) {
      mom += (w_num - i) * hist[i];
    }
    cout << fixed << setprecision(6) << (double)mom / (double)chi + 0.01
         << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::list;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set; // insert erase find count
using std::setprecision;
using std::stack;
using std::string;
using std::vector;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int>> PIII;

int main(void) {
  while (1) {
    int n;
    int w;
    cin >> n >> w;
    if (n == 0 && w == 0) {
      break;
    }

    int sep = (100 / w) + 1;
    std::cerr << "SEP = " << sep << endl;
    Vec<int> hist(sep, 0);

    int n_max = 0;
    int number;
    for (int i = 0; i < n; i++) {
      cin >> number;
      n_max = max(n_max, number);
      hist[number / w]++;
    }

    int h_max = 0;
    for (int i = 0; i < (int)hist.size(); i++) {
      h_max = max(h_max, hist[i]);
    }

    int w_num = n_max / w;
    std::cerr << w_num << endl;

    int mom = 0;
    int chi = w_num * h_max;

    for (int i = 0; i < (int)hist.size(); i++) {
      mom += (w_num - i) * hist[i];
    }
    cout << fixed << setprecision(6) << (double)mom / (double)chi + 0.01
         << endl;
  }
  return 0;
}
Problem p00864 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <string.h>
#define max(a, b) a > b ? a : b

int main(void) {
  int n, w, v[100], i, j, count[11], num, max;
  double sum;
  while (1) {
    scanf("%d%d", &n, &w);
    if (n == 0 && w == 0)
      break;
    max = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &v[i]);
      max = max(max, v[i]);
    }
    num = max / w + 1;
    memset(count, 0, sizeof(count));
    max = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < num; j++) {
        if (j * w <= v[i] && v[i] < (j + 1) * w)
          count[j]++;
      }
    }

    for (i = 0; i < num; i++)
      max = max(max, count[i]);
    sum = 0;
    if (num != 1) {
      for (i = 0; i < num; i++) {
        sum += ((double)(num - 1 - i) / (num - 1)) * ((double)count[i] / max);
      }
      printf("%.16f\\n", sum + 0.01);
    } else
      printf("1.01\\n");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
#define max(a, b) a > b ? a : b

int main(void) {
  int n, w, v[100], i, j, count[11], num, max;
  double sum;
  while (1) {
    scanf("%d%d", &n, &w);
    max = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &v[i]);
      max = max(max, v[i]);
    }
    num = max / w + 1;
    memset(count, 0, sizeof(count));
    max = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < num; j++) {
        if (j * w <= v[i] && v[i] < (j + 1) * w)
          count[j]++;
      }
    }

    for (i = 0; i < num; i++)
      max = max(max, count[i]);
    sum = 0;
    if (num != 1) {
      for (i = 0; i < num; i++) {
        sum += ((double)(num - 1 - i) / (num - 1)) * ((double)count[i] / max);
      }
      printf("%.16f\\n", sum + 0.01);
    } else
      printf("1.01\\n");
  }
  return 0;
}
Problem p00864 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for (ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n)&1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

int main() {
  int n, w, h;
  while (cin >> n >> w && (n + w) > 0) {
    int MAXW = 0;
    int MAXH = 0;

    vector<int> count(20, 0);
    REP(i, n) {
      cin >> h;
      count[h / w]++;
      MAXW = max(MAXW, h / w);
      MAXH = max(MAXH, count[h / w]);
    }
    double ans = 0.01;
    for (int i = 0; i < MAXW + 1; i++) {

      ans += (double)(MAXW - i) * count[i] / (MAXW * MAXH);
    }
    cout << fixed << setprecision(20) << ans << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for (ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n)&1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

int main() {
  int n, w, h;
  while (cin >> n >> w && (n + w) > 0) {
    int MAXW = 0;
    int MAXH = 0;

    vector<int> count(10, 0);
    REP(i, n) {
      cin >> h;
      count[h / w]++;
      MAXW = max(MAXW, h / w);
      MAXH = max(MAXH, count[h / w]);
    }
    double ans = 0.01;
    for (int i = 0; i < MAXW + 1; i++) {
      ans += (double)(MAXW - i) / MAXW * count[i] / MAXH;
    }
    cout << fixed << setprecision(20) << ans << endl;
  }
  return 0;
}
Problem p00864 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;

int main() {
  while (true) {
    int n, w;
    cin >> n >> w;
    if (n == 0)
      break;
    vector<int> hist(1000, 0);
    for (int i = 0; i < n; i++) {
      int p;
      cin >> p;
      p /= w;
      hist[p]++;
    }
    int num = 0, t = 0;

    rep(i, 1000) {
      num = max(num, hist[i]);
      if (hist[i] != 0)
        t = i;
    }
    double ans = 0.01;
    if (t == 0 or num == 0) {
      cout << 0.01 << endl;
      continue;
    }
    rep(i, 1000) { ans += ((double)hist[i] / num) * (1 - (double)i / t); }
    printf("%.6lf\\n", ans);
  }
}

Error: WA

Fixed submission:


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;

int main() {
  int n;
  while (cin >> n and n) {
    int w;
    cin >> w;
    vector<int> hist(n, 0);
    for (int i = 0; i < n; i++) {
      int p;
      cin >> p;
      p /= w;
      hist[p]++;
    }
    int num = 0, t = 0;
    rep(i, n) {
      num = max(num, hist[i]);
      if (hist[i] != 0)
        t = i;
    }
    double ans = 0.01;
    if (t == 0 or num == 0) {
      cout << 0.01 << endl;
      continue;
    }
    rep(i, t) { ans += ((double)hist[i] / (double)num) * (1 - i / (double)t); }
    printf("%.6lf\\n", ans);
  }
}
Problem p00864 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

#define LOG(x) // cerr << #x << " = " << x << endl

int main() {
  while (true) {
    int N, W;
    cin >> N >> W;
    if (N == 0 && W == 0)
      break;
    map<int, int> occ;
    for (int i = 0; i < N; ++i) {
      int v;
      cin >> v;
      occ[v / W]++;
    }
    int maxOcc = 0;
    int numBars = 0;
    for (auto &&iter : occ) {
      maxOcc = max(maxOcc, iter.second);
      numBars = max(numBars, iter.first + 1);
    }
    LOG(maxOcc);
    LOG(numBars);
    double ans = 0.01;
    for (auto &&iter : occ) {
      ans += (1.0 - (1.0 * iter.first / (numBars - 1))) *
             (1.0 * iter.second / maxOcc);
    }
    cout.setf(ios::fixed);
    cout.precision(6);
    cout << ans << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

#define LOG(x) // cerr << #x << " = " << x << endl

int main() {
  while (true) {
    int N, W;
    cin >> N >> W;
    if (N == 0 && W == 0)
      break;
    map<int, int> occ;
    for (int i = 0; i < N; ++i) {
      int v;
      cin >> v;
      occ[v / W]++;
    }
    int maxOcc = 0;
    int numBars = 0;
    for (auto &&iter : occ) {
      cerr << "bar[" << iter.first << "] = " << iter.second << endl;
      maxOcc = max(maxOcc, iter.second);
      numBars = max(numBars, iter.first + 1);
    }
    LOG(maxOcc);
    LOG(numBars);
    double ans = 0.01;
    for (auto &&iter : occ) {
      ans += (1.0 - (1.0 * iter.first / (numBars - 1))) *
             (1.0 * iter.second / maxOcc);
    }
    cout.setf(ios::fixed);
    cout.precision(6);
    cout << ans << endl;
  }
}
Problem p00864 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  while (1) {
    int n, w;
    cin >> n >> w;
    if (n == 0 && w == 0)
      break;
    int cnt[101] = {};
    int size = 0, ima = w, maxcnt = -1;
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      cnt[a / w]++;
      if (maxcnt < cnt[a / w])
        maxcnt = cnt[a / w];
      if (a / w > size)
        size = a / w;
    }
    size++;
    double ans = 0.01;
    for (int i = 0; i < size; i++)
      ans += (1.0 * cnt[i] / maxcnt) * (1.0 * (size - i - 1) / (size - 1));
    printf("%.16f\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  while (1) {
    int n, w;
    cin >> n >> w;

    int cnt[101] = {};
    int j = 0, ima = w, maxcnt = -1;
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      if (a < ima)
        cnt[j]++;
      else {
        ima += w, j++;
        if (a <= ima)
          cnt[j]++;
        continue;
      }
      if (maxcnt < cnt[j])
        maxcnt = cnt[j];
    }

    double ans = 0.01;
    int size = j + 1;
    for (int i = 0; i < size; i++)
      ans += (1.0 * cnt[i] / maxcnt) * (1.0 * (size - i - 1) / (size - 1));
    printf("%.16f\\n", ans);
  }
  return 0;
}
Problem p00864 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  cout << fixed << setprecision(7);
  int n, w;
  while (cin >> n >> w, n || w) {
    double res = 0.01;
    vector<int> inter(20, 0);
    for (int i = 0, v; i < n; i++) {
      cin >> v;
      inter[v / w]++;
    }
    while (inter.back() == 0) {
      inter.pop_back();
    }
    int maxi = -1;
    for (int i = 0; i < inter.size(); i++) {
      maxi = max(maxi, inter[i]);
    }
    for (int i = 0; i < inter.size(); i++) {
      res += (double)inter[i] / maxi *
             (inter.size() >= 2
                  ? (double)(inter.size() - i - 1) / (inter.size() - 1)
                  : 1.0);
    }
    cout << res << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  cout << fixed << setprecision(7);
  int n, w;
  while (cin >> n >> w, n || w) {
    double res = 0.01;
    vector<int> inter(n, 0);
    for (int i = 0, v; i < n; i++) {
      cin >> v;
      inter[v / w]++;
    }
    while (!inter.empty() && inter.back() == 0) {
      inter.pop_back();
      n--;
    }
    int maxi = -1;
    for (int i = 0; i < n; i++) {
      maxi = max(maxi, inter[i]);
    }
    for (int i = 0; i < n; i++) {
      res += (double)inter[i] / maxi *
             (n >= 2 ? (double)(n - i - 1) / (n - 1) : 1.0);
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00865 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <math.h>
#include <memory.h>
#include <stdio.h>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// FILE *in = freopen("input.txt", "r", stdin);

int n, m, k;
vector<int> cnt;

void back(int lev, int sum) {
  if (lev == n) {
    cnt[sum]++;
    return;
  }
  rep(i, m) { back(lev + 1, sum + i + 1); }
}

void process() {
  long long sum = 0;
  long double q = pow((long double)m, n);
  cnt.clear();
  cnt.assign(m * n + 1, 0);
  back(0, 0);
  for (int i = m * n; i > 0; i--) {
    int bills = i - k;
    if (bills < 1)
      bills = 1;
    sum += bills * cnt[i];
  }

  long double res = sum / q;
  printf("%.10Lf\\n", res);
}

int main() {
  while (true) {
    scanf("%d%d%d", &n, &m, &k);
    if (!n)
      break;
    process();
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <math.h>
#include <memory.h>
#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// FILE *in = freopen("input.txt", "r", stdin);

int n, m, k;

int count[50000000];

void back(int lev, int sum) {
  if (lev == n) {
    count[sum]++;
    return;
  }
  rep(i, m) { back(lev + 1, sum + i + 1); }
}

void process() {
  long long sum = 0;
  long double q = pow((long double)m, n);
  memset(count, 0, sizeof(count));
  back(0, 0);
  for (int i = m * n; i > 0; i--) {
    int bills = i - k;
    if (bills < 1)
      bills = 1;
    sum += bills * count[i];
  }

  long double res = sum / q;
  printf("%.10Lf\\n", res);
}

int main() {
  while (true) {
    scanf("%d%d%d", &n, &m, &k);
    if (!n)
      break;
    process();
  }
  return 0;
}
Problem p00865 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cmath>
#include <cstdio>
#include <iostream>
#include <string.h>

#define MAX 10000000

long long dp1[MAX];
long long dp2[MAX];

using namespace std;

int main(void) {
  int n, m, k;
  int i1, i2, i3;
  double ans;
  double poww;

  while (1) {
    cin >> n >> m >> k;
    if (n + m + k == 0)
      break;

    for (i1 = 0; i1 <= n * m; i1++) {
      dp1[i1] = 0;
      dp2[i1] = 0;
    }

    for (i1 = 1; i1 <= m; i1++) {
      dp1[i1] = 1;
    }

    for (i1 = 1; i1 < n; i1++) {
      for (i2 = 1; i2 <= n * m; i2++) {
        if (dp1[i2] != 0) {
          for (i3 = 1; i3 <= m; i3++)
            dp2[i2 + i3] += dp1[i2];
        }
      }

      for (i2 = 1; i2 <= n * m; i2++) {
        dp1[i2] = dp2[i2];
        dp2[i2] = 0;
      }
    }

    /*	for(i3=0;i3<=n*m;i3++){
                    cout<<i3<<" "<<dp1[i3]<<endl;
            }*/

    ans = 0;
    poww = pow((double)m, n);

    for (i1 = 1; i1 <= n * m; i1++) {
      if ((i1 - k) <= 0) {
        ans += (dp1[i1] / poww);
        // cout<<"1 "<<dp1[i1]<<" "<<poww<<endl;
      } else {
        ans += ((dp1[i1] / poww) * (double)(i1 - k));
        // cout<<i1-k<<" "<<dp1[i1]<<" "<<poww<<endl;
      }
    }

    printf("%.8lf\\n", ans);
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <string.h>

#define MAX 10000000

int dp1[MAX];
int dp2[MAX];

using namespace std;

int main(void) {
  int n, m, k;
  int i1, i2, i3;
  double ans;
  double poww;

  while (1) {
    cin >> n >> m >> k;
    if (n + m + k == 0)
      break;

    memset(dp1, 0, sizeof(dp1));
    memset(dp2, 0, sizeof(dp2));

    for (i1 = 1; i1 <= m; i1++) {
      dp1[i1] = 1;
    }

    for (i1 = 1; i1 < n; i1++) {
      for (i2 = 1; i2 <= n * m; i2++) {
        if (dp1[i2] != 0) {
          for (i3 = 1; i3 <= m; i3++)
            dp2[i2 + i3] += dp1[i2];
        }
      }

      for (i2 = 1; i2 <= n * m; i2++) {
        dp1[i2] = dp2[i2];
        dp2[i2] = 0;
      }
    }

    /*	for(i3=0;i3<=n*m;i3++){
                    cout<<i3<<" "<<dp1[i3]<<endl;
            }*/

    ans = 0;
    poww = pow((double)m, n);

    for (i1 = 1; i1 <= n * m; i1++) {
      if ((i1 - k) <= 0) {
        ans += (dp1[i1] / poww);
        // cout<<"1 "<<dp1[i1]<<" "<<poww<<endl;
      } else {
        ans += ((dp1[i1] / poww) * (double)(i1 - k));
        // cout<<i1-k<<" "<<dp1[i1]<<" "<<poww<<endl;
      }
    }

    printf("%.8lf\\n", ans);
  }
  return 0;
}
Problem p00865 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
// #define int long long
#define first fi
#define second se
using namespace std;
typedef pair<int, int> P;

int d[30][300010];

signed main() {
  int n, m, k;
  while (1) {
    cin >> n >> m >> k;
    if (n + m + k == 0)
      break;
    rep(i, 0, 30) rep(j, 0, 300010) d[i][j] = 0;
    d[0][0] = 1;
    rep(i, 0, n) {
      rep(j, i, 300000) {
        if (d[i][j] == 0)
          break;
        rep(l, 1, m + 1) { d[i + 1][j + l] += d[i][j]; }
      }
    }
    double sum = 0;
    rep(i, 0, 300000) {
      if (i <= k)
        sum += d[n][i];
      else
        sum += d[n][i] * (i - k);
    }
    rep(i, 0, n) sum /= (double)m;
    printf("%.14lf\\n", sum);
  }
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first fi
#define second se
using namespace std;
typedef pair<int, int> P;

int d[30][300010];

signed main() {
  int n, m, k;
  while (1) {
    cin >> n >> m >> k;
    if (n + m + k == 0)
      break;
    rep(i, 0, 30) rep(j, 0, 300010) d[i][j] = 0;
    d[0][0] = 1;
    rep(i, 0, n) {
      rep(j, i, 300000) {
        if (d[i][j] == 0)
          break;
        rep(l, 1, m + 1) { d[i + 1][j + l] += d[i][j]; }
      }
    }
    double sum = 0;
    rep(i, 0, 300000) {
      if (i <= k)
        sum += d[n][i];
      else
        sum += d[n][i] * (i - k);
    }
    rep(i, 0, n) sum /= (double)m;
    printf("%.14lf\\n", sum);
  }
}
Problem p00865 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

using LL = long long;

int main(void) {
  cout.precision(15);
  cout << fixed;
  for (;;) {
    int n, m, k;
    cin >> n >> m >> k;
    if (!n)
      break;
    // dp(i,j):=i??????m??¢???????????§j?????????????????°
    // dp[i][j] = dp[i-1][j-k](k=1~m)
    map<pair<int, int>, LL> dp;
    if (n == 1) {
      for (int kk = 1; kk <= m; ++kk) {
        dp[{1, kk}] = 1;
      }
    } else {
      dp[{0, 0}] = 1;
      for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= i * m; ++j) {
          for (int kk = 1; kk <= m; ++kk)
            dp[{i, j}] += dp[{i - 1, j - kk}];
        }
      }
    }
    LL ans = 0;
    LL div = 0;
    for (int j = 0; j <= n * m; ++j) {
      int score = max(1, j - k);
      ans += dp[{n, j}] * score;
      div += dp[{n, j}];
    }
    cout << (double)ans / div << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

using LL = long long;

int main(void) {
  cout.precision(15);
  cout << fixed;
  for (;;) {
    int n, m, k;
    cin >> n >> m >> k;
    if (!n)
      break;
    // dp(i,j):=i??????m??¢???????????§j?????????????????°
    // dp[i][j] = dp[i-1][j-k](k=1~m)
    map<pair<int, int>, LL> dp;
    dp[{0, 0}] = 1;
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j <= i * m; ++j) {
        for (int kk = 1; kk <= m; ++kk)
          dp[{i, j}] += dp[{i - 1, j - kk}];
      }
    }
    LL ans = 0;
    LL div = 0;
    for (int j = 0; j <= n * m; ++j) {
      int score = max(1, j - k);
      ans += dp[{n, j}] * score;
      div += dp[{n, j}];
    }
    cout << (double)ans / div << endl;
  }
  return 0;
}