結果
| 問題 |
No.1912 Get together 2
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 18:21:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,063 bytes |
| コンパイル時間 | 298 ms |
| コンパイル使用メモリ | 81,888 KB |
| 実行使用メモリ | 113,408 KB |
| 最終ジャッジ日時 | 2025-06-12 18:22:20 |
| 合計ジャッジ時間 | 11,789 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 WA * 30 |
ソースコード
n, m = map(int, input().split())
v = list(map(int, input().split()))
s_list = [input().strip() for _ in range(n)]
# Precompute for each box j, the total sum of slimes that can be assigned to it
total = [0] * m
compatible_boxes_per_slime = []
for i in range(n):
s = s_list[i]
compatible = []
for j in range(m):
if s[j] == 'o':
compatible.append(j)
total[j] += v[i]
compatible_boxes_per_slime.append(compatible)
# Create a list of (v_i, compatible_boxes) sorted descending by v_i
sorted_slimes = sorted(
[(v[i], compatible_boxes_per_slime[i]) for i in range(n)],
key=lambda x: -x[0]
)
box_sums = [0] * m
for (val, boxes) in sorted_slimes:
max_sum = -1
best_j = -1
best_total = -1
for j in boxes:
current_sum = box_sums[j]
if current_sum > max_sum or (current_sum == max_sum and total[j] > best_total):
max_sum = current_sum
best_j = j
best_total = total[j]
box_sums[best_j] += val
result = sum(s * s for s in box_sums)
print(result)
gew1fw