結果

問題 No.1912 Get together 2
ユーザー lam6er
提出日時 2025-04-15 23:13:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,202 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 81,636 KB
実行使用メモリ 120,272 KB
最終ジャッジ日時 2025-04-15 23:16:31
合計ジャッジ時間 13,264 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
v = list(map(int, input().split()))
allowed_boxes_list = []
for _ in range(n):
    s = input().strip()
    allowed = [j for j, c in enumerate(s) if c == 'o']
    allowed_boxes_list.append(allowed)

# Compute potential_sum for each box
potential_sum = [0] * m
for i in range(n):
    vi = v[i]
    for j in allowed_boxes_list[i]:
        potential_sum[j] += vi

# Sort slimes in descending order of value
sorted_slimes = sorted(zip(v, allowed_boxes_list), key=lambda x: -x[0])

current_sum = [0] * m

for value, allowed in sorted_slimes:
    # Find the maximum current sum among allowed boxes
    max_curr = max(current_sum[j] for j in allowed)
    # Collect all boxes with this maximum current sum
    candidates = [j for j in allowed if current_sum[j] == max_curr]
    # Among candidates, select the one with the highest potential_sum
    best_j = candidates[0]
    max_potential = potential_sum[best_j]
    for j in candidates[1:]:
        if potential_sum[j] > max_potential:
            max_potential = potential_sum[j]
            best_j = j
    current_sum[best_j] += value

# Calculate the total sum of squares
total = sum(x * x for x in current_sum)
print(total)
0