Problem:


Score: 500 points

Problem Statement

New AtCoder City has an infinite grid of streets, as follows:

At the center of the city stands a clock tower. Let (0, 0) be the coordinates of this point.

A straight street, which we will call East-West Main Street, runs east-west and passes the clock tower. It corresponds to the x-axis in the two-dimensional coordinate plane.

There are also other infinitely many streets parallel to East-West Main Street, with a distance of 1 between them. They correspond to the lines \ldots, y = -2, y = -1, y = 1, y = 2, \ldots in the two-dimensional coordinate plane.

A straight street, which we will call North-South Main Street, runs north-south and passes the clock tower. It corresponds to the y-axis in the two-dimensional coordinate plane.

There are also other infinitely many streets parallel to North-South Main Street, with a distance of 1 between them. They correspond to the lines \ldots, x = -2, x = -1, x = 1, x = 2, \ldots in the two-dimensional coordinate plane.

There are N residential areas in New AtCoder City. The i-th area is located at the intersection with the coordinates (X_i, Y_i) and has a population of P_i. Each citizen in the city lives in one of these areas.

The city currently has only two railroads, stretching infinitely, one along East-West Main Street and the other along North-South Main Street.

M-kun, the mayor, thinks that they are not enough for the commuters, so he decides to choose K streets and build a railroad stretching infinitely along each of those streets.

Let the walking distance of each citizen be the distance from his/her residential area to the nearest railroad.

M-kun wants to build railroads so that the sum of the walking distances of all citizens, S, is minimized.

For each K = 0, 1, 2, \dots, N, what is the minimum possible value of S after building railroads?

Constraints

1 \leq N \leq 15

-10 \ 000 \leq X_i \leq 10 \ 000

-10 \ 000 \leq Y_i \leq 10 \ 000

1 \leq P_i \leq 1 \ 000 \ 000

The locations of the N residential areas, (X_i, Y_i), are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 Y_1 P_1
X_2 Y_2 P_2
 :  :  :
X_N Y_N P_N

Output

Print the answer in N+1 lines.

The i-th line (i = 1, \ldots, N+1) should contain the minimum possible value of S after building railroads for the case K = i-1.

Sample Input 1

3
1 2 300
3 3 600
1 4 800

Sample Output 1

2900
900
0
0

When K = 0, the residents of Area 1, 2, and 3 have to walk the distances of 1, 3, and 1, respectively, to reach a railroad.

Thus, the sum of the walking distances of all citizens, S, is 1 \times 300 + 3 \times 600 + 1 \times 800 = 2900.

When K = 1, if we build a railroad along the street corresponding to the line y = 4 in the coordinate plane, the walking distances of the citizens of Area 1, 2, and 3 become 1, 1, and 0, respectively.

Then, S = 1 \times 300 + 1 \times 600 + 0 \times 800 = 900.

We have many other options for where we build the railroad, but none of them makes S less than 900.

When K = 2, if we build a railroad along the street corresponding to the lines x = 1 and x = 3 in the coordinate plane, all citizens can reach a railroad with the walking distance of 0, so S = 0. We can also have S = 0 when K = 3.

The figure below shows the optimal way to build railroads for the cases K = 0, 1, 2.

The street painted blue represents the roads along which we build railroads.

Sample Input 2

5
3 5 400
5 3 700
5 5 1000
5 7 700
7 5 400

Sample Output 2

13800
1600
0
0
0
0

The figure below shows the optimal way to build railroads for the cases K = 1, 2.

Sample Input 3

6
2 5 1000
5 2 1100
5 5 1700
-2 -5 900
-5 -2 600
-5 -5 2200

Sample Output 3

26700
13900
3200
1200
0
0
0

The figure below shows the optimal way to build railroads for the case K = 3.

Sample Input 4

8
2 2 286017
3 1 262355
2 -2 213815
1 -3 224435
-2 -2 136860
-3 -1 239338
-2 2 217647
-1 3 141903

Sample Output 4

2576709
1569381
868031
605676
366338
141903
0
0
0

The figure below shows the optimal way to build railroads for the case K = 4.



Sample input:
3
1 2 300
3 3 600
1 4 800


Sample output:
2900
900
0
0

Submission status: Wrong Answer

Solution code:
import sys, queue, math, copy, itertools, bisect, collections, heapq


def main():
    INF = 10 ** 15
    LI = lambda: [int(x) for x in sys.stdin.readline().split()]
    NI = lambda: int(sys.stdin.readline())

    N = NI()
    X = []
    Y = []
    P = []

    for _ in range(N):
        a, b, c = LI()
        X.append(a)
        Y.append(b)
        P.append(c)

    hor = [[0] * N for _ in range(2 ** N)]
    ver = [[0] * N for _ in range(2 ** N)]

    for i in range(2 ** N):
        for j in range(N):
            hor[i][j] = X[j]
            ver[i][j] = Y[j]
            k = i
            for b in range(N):
                if k & 1:
                    hor[i][j] = min(hor[i][j], abs(X[j] - X[b]))
                    ver[i][j] = min(ver[i][j], abs(Y[j] - Y[b]))
                k >>= 1

    ans = [INF] * (N + 1)
    for i in range(2 ** N):
        cnt = 0
        j = i
        for _ in range(N):
            cnt += j & 1
            j >>= 1

        j = i
        while True:
            s = 0
            for b in range(N):
                s += min(hor[j][b], ver[i-j][b]) * P[b]
            ans[cnt] = min(ans[cnt], s)
            if j == 0: break
            j -= 1
            j &= i

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, queue, math, copy, itertools, bisect, collections, heapq


def main():
    INF = 10 ** 15
    LI = lambda: [int(x) for x in sys.stdin.readline().split()]
    NI = lambda: int(sys.stdin.readline())

    N = NI()
    X = []
    Y = []
    P = []

    for _ in range(N):
        a, b, c = LI()
        X.append(a)
        Y.append(b)
        P.append(c)

    r = []
    st = 0
    for a, b, c in zip(X, Y, P):
        r.append(min(abs(a), abs(b)))
        st += r[-1] * c
    hor = [[0] * N for _ in range(2 ** N)]
    ver = [[0] * N for _ in range(2 ** N)]

    for i in range(2 ** N):
        for j in range(N):
            hor[i][j] = X[j]
            ver[i][j] = Y[j]
            k = i
            for b in range(N):
                if k & 1:
                    hor[i][j] = min(hor[i][j], abs(X[j] - X[b]))
                    ver[i][j] = min(ver[i][j], abs(Y[j] - Y[b]))
                k >>= 1

    ans = [st] * (N + 1)
    for i in range(2 ** N):
        cnt = 0
        j = i
        for _ in range(N):
            cnt += j & 1
            j >>= 1

        j = i
        while True:
            s = 0
            for b in range(N):
                s += min(hor[j][b], ver[i-j][b]) * P[b]
            ans[cnt] = min(ans[cnt], s)
            if j == 0: break
            j -= 1
            j &= i

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
INF = 10 ** 12

N = int(input())
X = [0] * N
Y = [0] * N
P = [0] * N
for i in range(N):
    X[i], Y[i], P[i] = map(int,input().split())

score_X = []

for i in range(2 ** N):
    x = []
    I = i
    for j in range(N):
        i = I
        score = abs(X[j]) * P[j]
        for k in range(N):
            if i & 1:
                score = min(score, abs(X[j] - X[k]) * P[j])
            i >>= 1
        x.append(score)
    score_X.append(x)

score_Y = []

for i in range(2 ** N):
    y = []
    I = i
    for j in range(N):
        i = I
        score = abs(Y[j]) * P[j]
        for k in range(N):
            if i & 1:
                score = min(score, abs(Y[j] - Y[k]) * P[j])
            i >>= 1
        y.append(score)
    score_Y.append(y)

ans = [INF] * (N + 1)

for i in range(2 ** N):
    cnt = 0
    for j in range(N):
        if (i >> j) & 1:
            cnt += 1
    j = i
    while True:
        score = 0
        for k in range(N):
            if not (i >> k) & 1:
                score += min(score_X[j][k], score_Y[i - j][k])
        ans[cnt] = min(ans[cnt], score)
        j = (j - 1) & i
        if not j:
            break

for i in range(N + 1):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
import numpy as np
#from copy import deepcopy
#from collections import deque


def run():
    N = int(sysread())
    INF = 1 << 50
    X, Y, P = [-1], [-1], [-1]
    ans = [INF] * (N+1)

    INF = 1 << 50
    hline = [0]
    vline = [0]
    dist_arr = np.zeros([2 * (N+1), N+1], dtype= np.int64)
    for i in range(1, N+1):
        x,y,p = map(int, sysread().split())
        X.append(x)
        Y.append(y)
        P.append(p)
        dist_arr[0, i] = abs(x) * p
        dist_arr[N+1, i] = abs(y) * p



    for i in range(1, N+1):
        v = X[i]
        h = Y[i]
        for k in range(1, N+1):
            # vertical
            dist_arr[i, k] = abs(v-X[k]) * P[k]
            dist_arr[N+1+i, k] = abs(h-Y[k]) * P[k]
    dist_arr = dist_arr[:, 1:]
    #print(dist_arr)

    for vals in product((0,1,2), repeat = N):
        xlines = set()
        ylines = set()
        idx = [0, N+1]
        for i, val in enumerate(vals, 1):
            if val == 0:
                continue
            elif val == 1:
                # vertical
                xlines.add(X[i])
                idx.append(i)
            else:
                ylines.add(Y[i])
                idx.append(N+1+i)
        k = len(xlines) + len(ylines)
        idx = np.array(idx)
        print(idx)
        #D = dist_arr[idx, :].min(axis = 0).sum()

        #ans[k] = min(ans[k], D)

    for a in ans:
        print(a)


if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
from numba import njit
import numpy as np
INF = 10**18

@njit('(i8, i8[:,:])')
def solve(N, XYP):
    X = XYP[:, 0]
    Y = XYP[:, 1]

    def calcCost(sign, A):
        ret = np.ones((1 << N, N), dtype=np.int64) * INF
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i in range(N):
                xyp = XYP[i]
                cost = abs(xyp[sign])
                for z in useA:
                    cost = min(cost, abs(xyp[sign] - z))
                ret[state][i] = cost * xyp[2]
        return ret

    costX = calcCost(0, X)
    costY = calcCost(1, Y)
    ans = np.ones(N + 1, dtype=np.int64) * INF

    return

    for state in range(pow(3, N)):
        stateX = 0
        stateY = 0
        M = N
        for _ in range(N):
            state, r = divmod(state, 3)
            stateX <<= 1
            stateY <<= 1
            if r == 0: M -= 1
            if r == 1: stateX |= 1
            if r == 2: stateY |= 1

        cx, cy = costX[stateX], costY[stateY]
        cost = np.minimum(cx, cy).sum()
        ans[M] = min(ans[M], cost)

    for a in ans:
        print(a)

def sol():
    N = int(input())
    XYP = np.asarray([list(map(int, input().split())) for _ in range(N)])
    solve(N, XYP)

sol()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
from numba import njit
import numpy as np
INF = 10**18

@njit
def solve(N, costX, costY):
    ans = np.ones(N, dtype=np.int64) * INF

    for state in range(pow(3, N)):
        stateX = 0
        stateY = 0
        M = N
        for _ in range(N):
            state, r = divmod(state, 3)
            stateX <<= 1
            stateY <<= 1
            if r == 0: M -= 1
            if r == 1: stateX |= 1
            if r == 2: stateY |= 1

        cx, cy = costX[stateX], costY[stateY]
        cost = np.minimum(cx, cy).sum()
        ans[M] = min(ans[M], cost)

    return ans

def sol():
    N = int(input())
    XYP = [tuple(map(int, input().split())) for _ in range(N)]
    XYP.sort(key=lambda xyp: xyp[2], reverse=False)

    X = [x for x, _, _ in XYP]
    Y = [y for _, y, _ in XYP]

    def calcCost(AP, A):
        ret = np.ones((1 << N, N), dtype=np.int64) * INF
        for state in range(1 << N):
            useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
            for i, (a, p) in enumerate(AP):
                cost = abs(a)
                for z in useA:
                    cost = min(cost, abs(a - z))
                ret[state][i] = cost * p
        return ret

    costX = calcCost([(x, p) for x, _, p in XYP], X)
    costY = calcCost([(y, p) for _, y, p in XYP], Y)

    ans = solve(N, costX, costY)
    print(*ans, sep='\n')

sol()

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [tuple(map(int,input().split())) for _ in range(N)]

#準備：S_の外延表記sを求める
def settify(S):
  s = []
  i = 0
  while S > 0:
    if (S & 1):  
      s.append(i)
    S = S >> 1
    i += 1
  return s

Sets = [settify(S_) for S_ in range(2**N)]
b = [2 ** i for i in range(N)] #2べき

def DP_solve(S, A, l, L): #l=0:x, l=1:y, L:最大本数
  if S == 0:
    return [0 for _ in range(L+1)]
  s = Sets[S]
  n = len(s)
  B = [(A[i][l],A[i][2]) for i in s]#位置,コスト(人口)
  B.sort()
  Q = [[0 for _ in range(n)] for _ in range(n)]#準備用
  for j in range(n):
    for k in range(j):#k < j
      Q[k][j] = sum([min(abs(B[l][0]),abs(B[l][0]-B[k][0]),abs(B[l][0]-B[j][0]))*B[l][1] for l in range(k+1,j)])
  DP = [[-1 for _ in range(n)] for _ in range(L+1)]
  #print(DP)
  for j in range(n):
    DP[1][j] = sum([min(abs(B[l][0]),abs(B[l][0]-B[j][0]))*B[l][1] for l in range(j)]) #i本目を置いて、最後がj番目の集落
  for i in range(2,L+1):
    DP[i][0] = DP[i-1][0]
    for j in range(1,n):
      DP[i][j] = min([DP[i-1][k]+Q[k][j] for k in range(j)])
      #i本目を置いて、最後がj番目の集落
      
  return [min([DP[i][j]+sum([min(abs(B[l][0]),abs(B[l][0]-B[j][0]))*B[l][1] for l in range(j+1,n)]) for j in range(n)]) if i >= 1 else sum([abs(B[l][0])*B[l][1] for l in range(n)]) for i in range(L+1)]

#1次元へ帰着
X = [DP_solve(S_,A,0, N) for S_ in range(2**N)]
Y = [DP_solve(S_,A,1, N) for S_ in range(2**N)]
#print(X)  
for k in range(N+1):#合計k本(大通り以外)
  ans = 10**10
  for S_ in range(2**N):#X側に集合S_が割り当てられる
    for i in range(k+1):#x軸平行にi本   
      #print(ans, X[S_][i] + Y[2**N-1-S_][k-i])
      ans = min(ans, X[S_][i] + Y[2**N-1-S_][k-i])
  print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
Y = []
P = []

for i in range(N):
    x, y, p = list(map(int, input().split()))
    X.append(x)
    Y.append(y)
    P.append(p)

pre_x = [[abs(X[j]) for j in range(N)] for i in range(2 ** N)]
pre_y = [[abs(Y[j]) for j in range(N)] for i in range(2 ** N)]

for i in range(2 ** N):
    for j in range(N):
        mx = abs(X[j])
        my = abs(Y[j])
        for k in range(N):
            if (i >> k) & 1:
                mx = min(mx, abs(X[k]-X[j]))
                my = min(my, abs(Y[k]-Y[j]))
        pre_x[i][j] = mx
        pre_y[i][j] = my

ans = [2 << 31 for i in range(N+1)]
for i in range(2 ** N):
    cnt = 0
    for j in range(N):
        if (i >> j) & 1:
            cnt += 1
    for j in reversed(range(0, i+1)):
        j = j & i
        cost = 0
        for k in range(N):
            if not ((i >> k) & 1):
                cost += min(pre_x[j][k], pre_y[i-j][k]) * P[k]
        ans[cnt] = min(ans[cnt], cost)

print(*ans, sep="\n")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import product


def read():
    N = int(input().strip())
    XYP = []
    for i in range(N):
        x, y, p = map(int, input().strip().split())
        XYP.append((x, y, p))
    return N, XYP


def solve(N, XYP, INF=10**9):
    ans = [INF for i in range(N+1)]
    vcost = [[0 for j in range(2**N)] for i in range(N)]
    hcost = [[0 for j in range(2**N)] for i in range(N)]

    # check 2**N pairs
    for intptn in range(2**N):
        for i, (xi, yi, pi) in enumerate(XYP):
            v = abs(xi)
            h = abs(yi)
            for j, (xj, yj, pj) in enumerate(XYP):
                if (intptn >> j) & 1 == 1:
                    v = min(v, abs(xj-xi))
                    h = min(h, abs(yj-yi))
            vcost[i][intptn] += v
            hcost[i][intptn] += h

    # check 3**N pairs
    for ptn in product(range(3), repeat=N):
        # split into two 2**N pairs
        intvptn = sum([1<<(N-i-1) for i in range(N) if ptn[i]==1])
        inthptn = sum([1<<(N-i-1) for i in range(N) if ptn[i]==2])
        s = 0
        for i in range(N):
            s += min(vcost[i][intvptn], hcost[i][inthptn]) * XYP[i][2]
        u = sum([t>0 for t in ptn])
        ans[u] = min(ans[u], s)

    for u in range(N+1):
        print(ans[u])


if __name__ == '__main__':
    inputs = read()
    solve(*inputs)

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
P = [p for _, _, p in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << N)]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, p) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state][i] = cost * p
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

ans = [[] for _ in range(N + 1)]
for state in product((0, 1, 2), repeat=N):
    stateX = 0
    stateY = 0
    M = N
    for s in state:
        stateX <<= 1
        stateY <<= 1
        if s == 0: M -= 1
        if s == 1: stateX |= 1
        if s == 2: stateY |= 1

    ans[M].append((costX[stateX], costY[stateY]))

exit()

for xy in ans:
    res = INF
    for a in xy:
        res = min(res, sum(map(min, zip(*a))))
    print(res)

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
P = [p for _, _, p in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << N)]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, p) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state][i] = cost * p
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

ans = [INF] * (N + 1)
for state in product((0, 1, 2), repeat=N):
    stateX = 0
    stateY = 0
    M = N
    for s in state:
        stateX <<= 1
        stateY <<= 1
        if s == 0: M -= 1
        if s == 1: stateX |= 1
        if s == 2: stateY |= 1

    cx = costX[stateX]
    cy = costY[stateY]
    cost = 0

    for x, y in zip(cx, cy):
        continue
        cost += min(x, y)

    if ans[M] > cost:
        ans[M] = cost

print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
P = [p for _, _, p in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << N)]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, _) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state][i] = cost
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

ans = [INF] * (N + 1)
for state in product((0, 1, 2), repeat=N):
    stateX = 0
    stateY = 0
    M = N
    for s in state:
        stateX <<= 1
        stateY <<= 1
        if s == 0: M -= 1
        if s == 1: stateX |= 1
        if s == 2: stateY |= 1

    cx = costX[stateX]
    cy = costY[stateY]
    cost = 0

    for i, (x, y) in enumerate(zip(cx, cy)):
        continue
        cost += p * min(cx[i], cy[i])

    if ans[M] > cost:
        ans[M] = cost

print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << N)]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, p) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state][i] = cost * p
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

ans = [INF] * (N + 1)
for state in product((0, 1, 2), repeat=N):
    stateX = 0
    stateY = 0
    M = N
    for s in state:
        stateX <<= 1
        stateY <<= 1
        if s == 0: M -= 1
        if s == 1: stateX |= 1
        if s == 2: stateY |= 1

    cx = costX[stateX]
    cy = costY[stateY]
    cost = 0

    for i in range(N):
        cost += cx[i] + cy[i]

    if ans[M] > cost:
        ans[M] = cost

print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << N)]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, p) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state][i] = cost * p
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

ans = [INF] * (N + 1)
for state in product((0, 1, 2), repeat=N):
    stateX = 0
    stateY = 0
    M = N
    for s in state:
        stateX <<= 1
        stateY <<= 1
        if s == 0: M -= 1
        if s == 1: stateX |= 1
        if s == 2: stateY |= 1

    cost = 0
    for x, y in zip(costX[stateX], costY[stateY]):
        continue
        cost += min(x, y)

    if ans[M] > cost:
        ans[M] = cost

print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << N)]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, p) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state][i] = cost * p
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

def makeState(state, sign):
    ret = 0
    for s in state:
        ret <<= 1
        if s == sign:
            ret |= 1
    return ret

ans = [INF] * (N + 1)
for state in product((0, 1, 2), repeat=N):
    stateX = 0
    stateY = 0
    M = N
    for s in state:
        stateX <<= 1
        stateY <<= 1
        if s == 0: M -= 1
        if s == 1: stateX |= 1
        if s == 2: stateY |= 1

    cx = costX[stateX]
    cy = costY[stateY]

    cost = 0
    for i in range(N):
        cost += min(cx[i], cx[i])

    if ans[M] > cost:
        ans[M] = cost

print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << N)]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, p) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state][i] = cost * p
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

def makeState(state, sign):
    ret = 0
    for s in state:
        ret <<= 1
        if s == sign:
            ret |= 1
    return ret

ans = [INF] * (N + 1)
for state in product((0, 1, 2), repeat=N):
    stateX = 0
    stateY = 0
    M = N
    for s in state:
        stateX <<= 1
        stateY <<= 1
        if s == 0: M -= 1
        if s == 1: stateX |= 1
        if s == 2: stateY |= 1

    cx = costX[stateX]
    cy = costY[stateY]

    cost = sum(min(x, y) for x, y in zip(cx, cy))
    continue

    if ans[M] > cost:
        ans[M] = cost

print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << N)]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, p) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state][i] = cost * p
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

def makeState(state, sign):
    ret = 0
    for s in state:
        ret <<= 1
        if s == sign:
            ret |= 1
    return ret

ans = [INF] * (N + 1)
for state in product((0, 1, 2), repeat=N):
    stateX = 0
    stateY = 0
    M = N
    for s in state:
        stateX <<= 1
        stateY <<= 1
        if s == 0: M -= 1
        if s == 1: stateX |= 1
        if s == 2: stateY |= 1

    cx = costX[stateX]
    cy = costY[stateY]

    continue

    cost = sum(min(x, y) for x, y in zip(cx, cy))

    if ans[M] > cost:
        ans[M] = cost

print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << N)]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, p) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state][i] = cost * p
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

def makeState(state, sign):
    ret = 0
    for s in state:
        ret <<= 1
        if s == sign:
            ret |= 1
    return ret

ans = [INF] * (N + 1)
for state in product((0, 1, 2), repeat=N):
    stateX = 0
    stateY = 0
    M = N
    for s in state:
        stateX <<= 1
        stateY <<= 1
        if s == 0: N -= 1
        if s == 1: stateX |= 1
        if s == 2: stateY |= 1
    continue

    cx = costX[stateX]
    cy = costY[stateY]

    cost = sum(min(x, y) for x, y in zip(cx, cy))

    if ans[M] > cost:
        ans[M] = cost

print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << N)]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, p) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state][i] = cost * p
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

def makeState(state, sign):
    ret = 0
    for s in state:
        ret <<= 1
        if s == sign:
            ret |= 1
    return ret

ans = [INF] * (N + 1)
for state in product((0, 1, 2), repeat=N):
    makeState(state, 1)
    makeState(state, 2)
    continue
    cx = costX[makeState(state, 1)]
    cy = costY[makeState(state, 2)]

    cost = sum(min(x, y) for x, y in zip(cx, cy))

    M = N - state.count(0)
    if ans[M] > cost:
        ans[M] = cost

print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << N)]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, p) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state][i] = cost * p
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

def makeState(state, sign):
    ret = 0
    for s in state:
        ret <<= 1
        if s == sign:
            ret |= 1
    return ret

ans = [INF] * (N + 1)
for state in product((0, 1, 2), repeat=N):
    for _ in range(N):
        pass
    continue
    cx = costX[makeState(state, 1)]
    cy = costY[makeState(state, 2)]

    cost = sum(min(x, y) for x, y in zip(cx, cy))

    M = N - state.count(0)
    if ans[M] > cost:
        ans[M] = cost

print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
XYP = [tuple(map(int, input().split())) for _ in range(N)]
X = [x for x, _, _ in XYP]
Y = [y for _, y, _ in XYP]
INF = 10**18

def calcCost(AP, A):
    ret = [[INF] * N for _ in range(1 << N)]
    for state in range(1 << N):
        useA = [a for i, a in enumerate(A) if (state & (1 << i)) != 0]
        for i, (a, p) in enumerate(AP):
            cost = abs(a)
            for z in useA:
                cost = min(cost, abs(a - z))
            ret[state][i] = cost * p
    return ret

costX = calcCost([(x, p) for x, _, p in XYP], X)
costY = calcCost([(y, p) for _, y, p in XYP], Y)

def makeState(state, sign):
    ret = 0
    for s in state:
        ret <<= 1
        if s == sign:
            ret |= 1
    return ret

ans = [INF] * (N + 1)
for state in product((0, 1, 2), repeat=N):
    continue
    cx = costX[makeState(state, 1)]
    cy = costY[makeState(state, 2)]

    cost = sum(min(x, y) for x, y in zip(cx, cy))

    M = N - state.count(0)
    if ans[M] > cost:
        ans[M] = cost

print(*ans, sep='\n')