Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;



const ll INF = 1e18;
signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    vector<pair<P,ll>> v(n);
    rep(i,n) cin >> v[i].fi.fi >> v[i].fi.se >> v[i].se;
    vector<ll> ans(n+1,INF);
    ll z=0;
    rep(j,n) z+=min(abs(v[j].fi.fi),abs(v[j].fi.se))*v[j].se;
    chmin(ans[0],z);
    rep(i,1<<n){
        int x=0;
        rep(j,n){
            if((1<<j)&i) x++;
        }
        int no=n-x;
        for (int y = (1 << y) - 1; y < (1 << no); ){
            
            vector<ll> len(n);
            rep(k,n) len[k]=min(abs(v[k].fi.fi),abs(v[k].fi.se))*v[k].se;
            map<int,int>mpx;
            map<int,int>mpy;
            int cnt=0;
            rep(k,n){
                if((1<<k)&i){
                    if(mpx[v[k].fi.fi]==0){
                        cnt++;
                        mpx[v[k].fi.fi]=1;
                        rep(l,n){
                            chmin(len[l],abs(v[k].fi.fi-v[l].fi.fi)*v[l].se);
                        }
                    }
                }
            }
            rep(k,y){
                if((1<<k)&j){
                    if(mpy[v[k].fi.se]==0){
                        cnt++;
                        mpy[v[k].fi.se]=1;
                        rep(l,n){
                            chmin(len[l],abs(v[k].fi.se-v[l].fi.se)*v[l].se);
                        }
                    }
                }
            }
            if(cnt>n)break;
            ll res=0;
            rep(k,n) res+=len[k];
            chmin(ans[cnt],res);
        }
        }
    }
    rep(i,n){
        chmin(ans[i+1],ans[i]);
    }
    rep(i,n+1){
        cout<<ans[i]<<endl;
    }
}



Compiler output:
a.cc: In function 'int main()':
a.cc:71:27: error: 'j' was not declared in this scope
   71 |                 if((1<<k)&j){
      |                           ^
a.cc: At global scope:
a.cc:17:18: error: expected unqualified-id before 'for'
   17 | #define rep(i,n) for(int i=0;i<(n);i++)
      |                  ^~~
a.cc:88:5: note: in expansion of macro 'rep'
   88 |     rep(i,n){
      |     ^~~
a.cc:88:9: error: 'i' does not name a type
   88 |     rep(i,n){
      |         ^
a.cc:17:30: note: in definition of macro 'rep'
   17 | #define rep(i,n) for(int i=0;i<(n);i++)
      |                              ^
a.cc:88:9: error: 'i' does not name a type
   88 |     rep(i,n){
      |         ^
a.cc:17:36: note: in definition of macro 'rep'
   17 | #define rep(i,n) for(int i=0;i<(n);i++)
      |                                    ^
a.cc:17:18: error: expected unqualified-id before 'for'
   17 | #define rep(i,n) for(int i=0;i<(n);i++)
      |                  ^~~
a.cc:91:5: note: in expansion of macro 'rep'
   91 |     rep(i,n+1){
      |     ^~~
a.cc:91:9: error: 'i' does not name a type
   91 |     rep(i,n+1){
      |         ^
a.cc:17:30: note: in definition of macro 'rep'
   17 | #define rep(i,n) for(int i=0;i<(n);i++)
      |                              ^
a.cc:91:9: error: 'i' does not name a type
   91 |     rep(i,n+1){
      |         ^
a.cc:17:36: note: in definition of macro 'rep'
   17 | #define rep(i,n) for(int i=0;i<(n);i++)
      |                                    ^
a.cc:94:1: error: expected declaration before '}' token
   94 | }
      | ^