alexjercan/bugnet huggingface dataset:
Problem p02604 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N, M, H, W, Q, K, A, B;
string S;
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL << 58);

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}

vec x(15), y(15), p(15), ans(16, INF);

void dfs(vec &choose, vec &see, int now) {
  ll sz = choose.size();
  if (now == N) {
    ll res = 0;
    for (ll v : see) {
      ll dist = min(abs(x[v]), abs(y[v]));
      for (ll to : choose) {
        chmin(dist, to >= N ? abs(y[to - N] - y[v]) : abs(x[to] - x[v]));
      }
      res += dist * p[v];
    }
    chmin(ans[sz], res);
  } else {
    see.push_back(now);
    dfs(choose, see, now + 1);
    see.pop_back();
    choose.push_back(now);
    dfs(choose, see, now + 1);
    choose.pop_back();
    choose.push_back(now + N);
    dfs(choose, see, now + 1);
    choose.pop_back();
  }
}

int main() {
  cin >> N;
  rep(i, N) cin >> x[i] >> y[i] >> p[i];
  vec choose(0), see(0);
  dfs(choose, see, 0);
  rep(i, N + 1) cout << ans[i] << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N, M, H, W, Q, K, A, B;
string S;
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL << 58);

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}

vec x(15), y(15), p(15), ans(16, INF);

void dfs(vec &choose, int now) {
  ll sz = choose.size();
  if (now == N) {
    vec dist(N);
    rep(i, N) dist[i] = min(abs(x[i]), abs(y[i]));
    for (ll c : choose) {
      rep(i, N) {
        chmin(dist[i], (c >= N ? abs(y[c - N] - y[i]) : abs(x[c] - x[i])));
      }
    }
    ll res = 0;
    rep(i, N) res += dist[i] * p[i];
    chmin(ans[sz], res);
  } else {
    dfs(choose, now + 1);
    choose.push_back(now);
    dfs(choose, now + 1);
    choose.pop_back();
    choose.push_back(now + N);
    dfs(choose, now + 1);
    choose.pop_back();
  }
}

int main() {
  cin >> N;
  rep(i, N) cin >> x[i] >> y[i] >> p[i];
  vec choose(0);
  dfs(choose, 0);
  rep(i, N + 1) cout << ans[i] << endl;
}
Problem p02604 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vec<ll> X(N), Y(N), P(N);
  for (int i = 0; i < N; i++)
    cin >> X[i] >> Y[i] >> P[i];
  ll inf = 1e18;
  vec<ll> ans(N + 1, inf);
  vvec<ll> dpx(1 << N, vec<ll>(N, inf));
  vvec<ll> dpy(1 << N, vec<ll>(N, inf));
  for (int i = 0; i < N; i++) {
    dpx[0][i] = abs(X[i]);
    dpy[0][i] = abs(Y[i]);
    for (int S = 0; S < (1 << N); S++) {
      for (int j = 0; j < N; j++)
        if (!(S >> j & 1)) {
          int T = S ^ (1 << j);
          dpx[T][i] = min(dpx[S][i], abs(X[i] - X[j]));
          dpy[T][i] = min(dpy[S][i], abs(Y[i] - Y[j]));
        }
    }
  }
  for (int S = 0; S < (1 << N); S++) {
    for (int T = S; T >= 0; T = (T - 1) & S) {
      ll val = 0;
      int A = T, B = S ^ T;
      for (int i = 0; i < N; i++)
        val += min(dpx[A][i], dpy[B][i]) * P[i];
      int n = __builtin_popcount(S);
      ans[n] = min(ans[n], val);
      if (!T)
        break;
    }
  }
  for (auto &x : ans)
    cout << x << "\\n";
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vec<ll> X(N), Y(N), P(N);
  for (int i = 0; i < N; i++)
    cin >> X[i] >> Y[i] >> P[i];
  ll inf = 1e18;
  vec<ll> ans(N + 1, inf);
  for (int S = 0; S < (1 << N); S++) {
    for (int T = S; T >= 0; T = (T - 1) & S) {
      vec<ll> x = {0}, y = {0};
      ll val = 0;
      for (int i = 0; i < N; i++)
        if (!(S >> i & 1)) {
          ll now = min(abs(X[i]), abs(Y[i]));
          for (int j = 0; j < N; j++)
            if (S >> j & 1) {
              if (T >> j & 1)
                now = min(now, abs(X[i] - X[j]));
              else
                now = min(now, abs(Y[i] - Y[j]));
            }
          val += now * P[i];
        }
      int n = __builtin_popcount(S);
      ans[n] = min(ans[n], val);
      if (!T)
        break;
    }
  }
  for (auto &x : ans)
    cout << x << "\\n";
}
Problem p02604 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
const long long inf = 1000000000000000000ll;

int n;
struct node {
  int x, y;
  long long p;
} t[20];

long long ans[20];
long long mn[20];

void dfs(int p, int cnt) {
  if (p == n) {
    long long ret = 0;
    for (int i = 0; i < n; i++)
      ret += mn[i];
    ans[cnt] = min(ans[cnt], ret);
    return;
  }

  dfs(p + 1, cnt);

  long long tmp[20];

  // x
  for (int i = 0; i < n; i++)
    tmp[i] = mn[i];
  for (int i = 0; i < n; i++)
    mn[i] = min(mn[i], abs(t[i].x - t[p].x) * t[i].p);
  dfs(p + 1, cnt + 1);
  for (int i = 0; i < n; i++)
    mn[i] = tmp[i];

  // y
  for (int i = 0; i < n; i++)
    tmp[i] = mn[i];
  for (int i = 0; i < n; i++)
    mn[i] = min(mn[i], abs(t[i].y - t[p].y) * t[i].p);
  dfs(p + 1, cnt + 1);
  for (int i = 0; i < n; i++)
    mn[i] = tmp[i];
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%lld", &t[i].x, &t[i].y, &t[i].p);
  }
  for (int i = 0; i <= n; i++)
    ans[i] = inf;
  for (int i = 0; i < n; i++) {
    mn[i] = min(abs(t[i].x), abs(t[i].y)) * t[i].p;
  }
  dfs(0, 0);
  for (int i = 0; i <= n; i++) {
    printf("%lld\\n", ans[i]);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

long long ans[20];
const long long inf = 1000000000000000000ll;

int n;
struct peo {
  long long x, y, p;
} a[20];

int ord[20];

long long calc(int sta) {
  long long ret = inf;
  int cnt = __builtin_popcount(sta);

  vector<int> v;

  for (int i = 0; i < n; i++)
    if ((sta >> i) & 1)
      v.push_back(i + 1);

  for (int i = 0; i < (1 << cnt); i++) {
    long long tmp = 0;

    for (int j = 0; j < cnt; j++)
      ord[v[j]] = ((i >> j) & 1);

    for (int j = 0; j < n; j++)
      if (((sta >> j) & 1) == 0) {
        long long res = min(abs(a[j + 1].x), abs(a[j + 1].y)) * a[j + 1].p;
        for (auto &now : v) {
          if (ord[now] == 1)
            res = min(res, abs(a[j + 1].x - a[now].x) * a[j + 1].p);
          else
            res = min(res, abs(a[j + 1].y - a[now].y) * a[j + 1].p);
        }
        tmp += res;
      }
    ret = min(ret, tmp);
  }

  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld%lld", &a[i].x, &a[i].y, &a[i].p);
  }

  for (int i = 0; i <= n; i++)
    ans[i] = inf;

  int allS = (1 << n);
  for (int i = 0; i < allS; i++) {
    int tmp = __builtin_popcount(i);
    ans[tmp] = min(ans[tmp], calc(i));
  }

  for (int i = 0; i <= n; i++)
    printf("%lld\\n", ans[i]);
  return 0;
}
Problem p02604 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <stdexcept>
#include <vector>
using namespace std;

void dfs(int i, int N, int K, vector<long long> &minS, vector<int> &railsX,
         vector<int> &railsY, vector<int> &X, vector<int> &Y, vector<int> &P) {
  if (i == N) {
    // update minS
    long long S = 0;
    for (int i = 0; i < N; i++) {
      int distance = 1000000;
      for (int x : railsX)
        distance = min(distance, abs(x - X[i]));
      for (int y : railsY)
        distance = min(distance, abs(y - Y[i]));
      S += (long long)distance * P[i];
    }
    minS[K] = min(S, minS[K]);
    return;
  }

  dfs(i + 1, N, K, minS, railsX, railsY, X, Y, P);
  railsX.push_back(X[i]);
  dfs(i + 1, N, K + 1, minS, railsX, railsY, X, Y, P);
  railsX.pop_back();
  railsY.push_back(Y[i]);
  dfs(i + 1, N, K + 1, minS, railsX, railsY, X, Y, P);
  railsY.pop_back();
}

int main() {
  int N;
  cin >> N;

  vector<int> X(N);
  vector<int> Y(N);
  vector<int> P(N);
  for (int i = 0; i < N; i++)
    cin >> X[i] >> Y[i] >> P[i];

  vector<long long> minS(N + 1, 100000000002);
  vector<int> railsX = {0}, railsY = {0};
  dfs(0, N, 0, minS, railsX, railsY, X, Y, P);
  for (int i = 0; i <= N; i++)
    cout << minS[i] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <stdexcept>
#include <vector>
using namespace std;

void dfs(int i, int N, int K, vector<long long> &minS, vector<int> &railsX,
         vector<int> &railsY, vector<int> &X, vector<int> &Y, vector<int> &P) {
  if (i == N) {
    // update minS
    long long S = 0;
    for (int i = 0; i < N; i++) {
      long long distance = 1000000;
      for (int x : railsX)
        distance = min(distance, (long long)abs(x - X[i]));
      for (int y : railsY)
        distance = min(distance, (long long)abs(y - Y[i]));
      S += distance * P[i];
    }
    minS[K] = min(S, minS[K]);
    return;
  }

  dfs(i + 1, N, K, minS, railsX, railsY, X, Y, P);
  railsX.push_back(X[i]);
  dfs(i + 1, N, K + 1, minS, railsX, railsY, X, Y, P);
  railsX.pop_back();
  railsY.push_back(Y[i]);
  dfs(i + 1, N, K + 1, minS, railsX, railsY, X, Y, P);
  railsY.pop_back();
}

int main() {
  int N;
  cin >> N;

  vector<int> X(N);
  vector<int> Y(N);
  vector<int> P(N);
  for (int i = 0; i < N; i++)
    cin >> X[i] >> Y[i] >> P[i];

  vector<long long> minS(N + 1, 100000000002);
  vector<int> railsX = {0}, railsY = {0};
  dfs(0, N, 0, minS, railsX, railsY, X, Y, P);
  for (int i = 0; i <= N; i++)
    cout << minS[i] << endl;
  return 0;
}
Problem p02604 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n, x[20], y[20];
int m[20];
long long rlt[20], w[20];

int v[20], szv, vv[20], szvv;

void DFS(int c) {
  if (c == n) {
    int cn = 0;

    szv = szvv = 0;

    for (int i = 0; i < n; i++) {
      if (m[i])
        v[szv++] = i, cn++;
      else
        vv[szvv++] = i;
    }

    long long r = 0;
    for (int ii = 0; ii < szvv; ii++) {
      int i = vv[ii];

      int mn = min(abs(x[i]), abs(y[i]));
      for (int jj = 0; jj < szv; jj++) {
        int j = v[jj];
        if (m[j] == 1)
          mn = min(mn, abs(x[i] - x[j]));
        else if (m[j] == 2)
          mn = min(mn, abs(y[i] - y[j]));
      }

      r += 1ll * mn * w[i];
      if (r > rlt[cn])
        return;
    }
    for (int i = cn; i <= n; i++) {
      if (rlt[i] > r) {
        rlt[i] = r;
      } else
        return;
    }
  } else {
    m[c] = 0;
    DFS(c + 1);
    m[c] = 1;
    DFS(c + 1);
    m[c] = 2;
    DFS(c + 1);
  }
}

int id[20], xx[20], yy[20], ww[20];

int main() {
  srand(time(0));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%lld", &xx[i], &yy[i], &ww[i]);
    id[i] = i;
  }
  random_shuffle(id, id + n);
  for (int i = 0; i < n; i++)
    x[i] = xx[id[i]], y[i] = yy[id[i]], w[i] = ww[id[i]];

  memset(m, 0, sizeof(m));
  memset(rlt, 127, sizeof(rlt));

  DFS(0);

  for (int i = 0; i <= n; i++) {
    printf("%lld\\n", rlt[i]);
  }
}


Error: TLE

Fixed submission:

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

int n, x[20], y[20];
int m[20];
long long rlt[20], w[20];

void DFS(int c) {
  if (c == n) {
    int cn = 0;
    for (int i = 0; i < n; i++) {
      if (m[i])
        cn++;
    }

    long long r = 0;
    for (int i = 0; i < n; i++) {
      if (m[i])
        continue;

      int mn = min(abs(x[i]), abs(y[i]));
      for (int j = 0; j < n; j++) {
        if (m[j] == 1)
          mn = min(mn, abs(x[i] - x[j]));
        else if (m[j] == 2)
          mn = min(mn, abs(y[i] - y[j]));
      }

      r += 1ll * mn * w[i];
      if (r > rlt[cn])
        return;
    }
    for (int i = cn; i <= n; i++) {
      if (rlt[i] > r) {
        rlt[i] = r;
      } else
        break;
    }
    return;
  } else {
    m[c] = 0;
    DFS(c + 1);
    m[c] = 1;
    DFS(c + 1);
    m[c] = 2;
    DFS(c + 1);
  }
}

int id[20], xx[20], yy[20], ww[20];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%lld", &xx[i], &yy[i], &ww[i]);
    id[i] = i;
  }
  random_shuffle(id, id + n);
  for (int i = 0; i < n; i++)
    x[i] = xx[id[i]], y[i] = yy[id[i]], w[i] = ww[id[i]];

  memset(m, 0, sizeof(m));
  memset(rlt, 127, sizeof(rlt));

  DFS(0);

  for (int i = 0; i <= n; i++) {
    printf("%lld\\n", rlt[i]);
  }
}
Problem p02604 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

template <class T> std::vector<T> vec(int len, T elem) {
  return std::vector<T>(len, elem);
}

using lint = long long;

constexpr lint INF = 1LL << 60;

void solve() {
  int n;
  std::cin >> n;

  std::vector<lint> xs(n), ys(n), ps(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> xs[i] >> ys[i] >> ps[i];
  }

  auto xds = vec(n, vec(1 << n, INF));
  auto yds = xds;

  for (int i = 0; i < n; ++i) {
    for (int b = 0; b < (1 << n); ++b) {
      {
        auto &cost = xds[i][b];
        cost = std::abs(xs[i]);
        for (int j = 0; j < n; ++j) {
          if ((b >> j) & 1)
            cost = std::min(cost, std::abs(xs[i] - xs[j]));
        }
      }

      {
        auto &cost = yds[i][b];
        cost = std::abs(ys[i]);
        for (int j = 0; j < n; ++j) {
          if ((b >> j) & 1)
            cost = std::min(cost, std::abs(ys[i] - ys[j]));
        }
      }
    }
  }

  std::vector<lint> ans(n + 1, INF);

  for (int b = 0; b < (1 << n); ++b) {
    std::vector<int> is;
    for (int i = 0; i < n; ++i) {
      if ((b >> i) & 1)
        is.push_back(i);
    }

    int k = is.size();
    for (int c = 0; c < (1 << k); ++c) {
      int xb = 0, yb = 0;
      for (int j = 0; j < k; ++j) {
        int i = is[j];
        if ((c >> j) & 1) {
          xb |= (1 << i);
        } else {
          yb |= (1 << i);
        }
      }

      lint cost = 0;
      for (int i = 0; i < n; ++i) {
        lint dist = std::min(xds[i][xb], yds[i][yb]);
        cost += dist * ps[i];
      }

      ans[k] = std::min(ans[k], cost);
    }
  }

  for (auto a : ans)
    std::cout << a << "\\n";
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  solve();

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using lint = long long;

constexpr lint INF = 1LL << 60;

void solve() {
  int n;
  std::cin >> n;

  std::vector<lint> xs(n), ys(n), ps(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> xs[i] >> ys[i] >> ps[i];
  }

  std::vector<lint> ans(n + 1, INF);

  for (int b = 0; b < (1 << n); ++b) {
    std::vector<int> is;
    for (int i = 0; i < n; ++i) {
      if ((b >> i) & 1)
        is.push_back(i);
    }

    int k = is.size();
    for (int c = 0; c < (1 << k); ++c) {
      std::vector<lint> xls{0}, yls{0};
      for (int j = 0; j < k; ++j) {
        int i = is[j];
        if ((c >> j) & 1) {
          xls.push_back(xs[i]);
        } else {
          yls.push_back(ys[i]);
        }
      }

      lint cost = 0;
      for (int i = 0; i < n; ++i) {
        lint dist = INF;
        for (auto x : xls) {
          dist = std::min(dist, std::abs(xs[i] - x));
        }
        for (auto y : yls) {
          dist = std::min(dist, std::abs(ys[i] - y));
        }
        cost += dist * ps[i];
      }

      ans[k] = std::min(ans[k], cost);
    }
  }

  for (auto a : ans)
    std::cout << a << "\\n";
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  solve();

  return 0;
}
Problem p02604 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ze(ll a) {
  if (a < 0)
    return -a;
  return a;
}
int main() {
  int N;
  cin >> N;
  vector<ll> X(N);
  vector<ll> Y(N);
  vector<ll> P(N);
  for (int i = 0; i < N; i++)
    cin >> X[i] >> Y[i] >> P[i];
  ll tate[321600][20];
  ll yoko[321600][20];
  ll lx[20];
  ll ly[20];
  int si;
  for (int i = 0; i < 1 << N; i++) {
    int i_ = i;
    lx[0] = 0;
    si = 1;
    ly[0] = 0;
    for (int j = 0; j < N; j++) {
      if (i_ % 2) {
        lx[si] = X[j];
        ly[si] = Y[j];
        si++;
      }
      i_ /= 2;
    }
    for (int j = 0; j < N; j++) {
      ll tkj = ze(Y[j]);
      ll ykj = ze(X[j]);
      for (int k = 0; k < si; k++) {
        tkj = min(tkj, ze(X[j] - lx[k]));
        ykj = min(ykj, ze(Y[j] - ly[k]));
      }
      tate[i][j] = tkj;
      yoko[i][j] = ykj;
    }
  }
  ll cnt = 1;
  for (int i = 0; i < N; i++)
    cnt *= 3;
  ll ans[20];
  for (int i = 0; i <= N; i++)
    ans[i] = 1e17;
  int bi[20];
  bi[0] = 1;
  for (int i = 1; i < N; i++)
    bi[i] = bi[i - 1] * 2;
  for (int i = 0; i < cnt; i++) {
    int i_ = i;
    int num = N;
    int tt = 0;
    int yk = 0;
    ll kj = 0;
    for (int j = 0; j < N; j++) {
      if (i_ % 3 == 0) {
        num--;
      }
      if (i_ % 3 == 1) {
        tt += bi[j];
      }
      if (i_ % 3 == 2) {
        yk += bi[j];
      }
      i_ /= 3;
    }
    for (int j = 0; j < N; j++) {
      kj += P[j] * min(tate[tt][j], yoko[yk][j]);
    }
    ans[num] = min(ans[num], kj);
  }
  for (int i = 0; i <= N; i++)
    cout << ans[i] << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ze(ll a) {
  if (a < 0)
    return -a;
  return a;
}
int main() {
  int N;
  cin >> N;
  vector<ll> X(N);
  vector<ll> Y(N);
  vector<ll> P(N);
  for (int i = 0; i < N; i++)
    cin >> X[i] >> Y[i] >> P[i];
  vector<ll> tate(1 << N);
  vector<ll> yoko(1 << N);
  ll lx[20];
  ll ly[20];
  int si = 0;
  for (int i = 0; i < 1 << N; i++) {
    int i_ = i;
    lx[0] = 0;
    si++;
    ly[0] = 0;
    for (int j = 0; j < N; j++) {
      if (i_ % 2) {
        lx[si] = X[j];
        ly[si] = Y[j];
        si++;
      }
      i_ /= 2;
    }
    tate[i] = 0;
    yoko[i] = 0;
    for (int j = 0; j < N; j++) {
      ll tkj = ze(Y[j]);
      ll ykj = ze(X[j]);
      for (int k = 0; k < si; k++) {
        tkj = min(tkj, ze(X[j] - lx[k]));
        ykj = min(ykj, ze(Y[j] - ly[k]));
      }
      tate[i] += tkj * P[j];
      yoko[i] += ykj * P[j];
    }
  }
  ll cnt = 1;
  for (int i = 0; i < N; i++)
    cnt *= 3;
  ll ans[20];
  for (int i = 0; i <= N; i++)
    ans[i] = 1e17;
  for (int i = 0; i < cnt; i++) {
    int i_ = i;
    int num = N;
    int tt = 0;
    int yk = 0;
    for (int j = 0; j < N; j++) {
      tt *= 2;
      yk *= 2;
      if (i_ % 3 == 0) {
        num--;
      }
      if (i_ % 3 == 1) {
        tt++;
      }
      if (i_ % 3 == 2) {
        yk++;
      }
      i_ /= 3;
    }
    ans[num] = min(ans[num], min(tate[tt], yoko[yk]));
  }
  for (int i = 0; i <= N; i++)
    cout << ans[i] << endl;
}
Problem p02604 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
////////////////////////////////???????????????CHECK THIS
///OUT???????????????//////////////////////////////
typedef long long ll;
////////////////////////////////???????????????CHECK THIS
///OUT???????????????//////////////////////////////
#define pii pair<int, int>
#define endl "\\n"
const int N = 16 + 1;
const int M = 1e9 + 7;
const ll inf = 1e18;
int n, id1, id2, ind, c, p1[N], p2[N], p[N], x[N], y[N];
ll ans[N], s;
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n;
  int g = 1;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> p[i];
    ans[i] = inf;
    g *= 3;
  }
  ans[n] = inf;
  for (int mask = 0; mask < g; mask++) {
    id1 = id2 = ind = s = 0;
    c = mask;
    while (c > 0 && (id1 + id2) < n) {
      if (c % 3 == 1)
        p1[id1++] = x[ind];
      else if (c % 3 == 2)
        p2[id2++] = y[ind];
      ind++;
      c /= 3;
    }
    for (int i = 0; i < n; i++) {
      int mn = min(abs(x[i]), abs(y[i]));
      for (int k = 0; k < id1; k++)
        mn = min(mn, abs(x[i] - p1[k]));
      for (int k = 0; k < id2; k++)
        mn = min(mn, abs(y[i] - p2[k]));
      s += 1ll * mn * p[i];
    }
    ans[id1 + id2] = min(ans[id1 + id2], s);
  }
  for (int i = 0; i <= n; i++)
    cout << ans[i] << "\\n";
  return 0;
}
/*

/
*/


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
////////////////////////////////???????????????CHECK THIS
///OUT???????????????//////////////////////////////
typedef long long ll;
////////////////////////////////???????????????CHECK THIS
///OUT???????????????//////////////////////////////
#define pii pair<int, int>
#define endl "\\n"
const int N = 16 + 1;
const int M = 1e9 + 7;
const ll inf = 1e18;
int n, id1, id2, ind, c, p1[N], p2[N], p[N];
;
pii a[N];
ll ans[N], s;
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n;
  int g = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i].f >> a[i].s >> p[i];
    ans[i] = inf;
    g *= 3;
  }
  ans[n] = inf;
  for (int mask = 0; mask < g; mask++) {
    id1 = id2 = ind = s = 0;
    c = mask;
    while (c > 0 && (id1 + id2) < n) {
      if (c % 3 == 1)
        p1[id1++] = a[ind].f;
      else if (c % 3 == 2)
        p2[id2++] = a[ind].s;
      ind++;
      c /= 3;
    }
    for (int i = 0; i < n; i++) {
      int mn = min(abs(a[i].f), abs(a[i].s));
      for (int k = 0; k < id1; k++)
        mn = min(mn, abs(a[i].f - p1[k]));
      for (int k = 0; k < id2; k++)
        mn = min(mn, abs(a[i].s - p2[k]));
      s += 1ll * mn * p[i];
    }
    ans[id1 + id2] = min(ans[id1 + id2], s);
  }
  for (int i = 0; i <= n; i++)
    cout << ans[i] << "\\n";
  return 0;
}
/*

/
*/