結果
問題 |
No.1912 Get together 2
|
ユーザー |
![]() |
提出日時 | 2025-06-12 13:04:52 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 906 bytes |
コンパイル時間 | 194 ms |
コンパイル使用メモリ | 82,704 KB |
実行使用メモリ | 98,224 KB |
最終ジャッジ日時 | 2025-06-12 13:10:00 |
合計ジャッジ時間 | 11,214 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 count of slimes per box count = [0] * m for s in s_list: for j in range(m): if s[j] == 'o': count[j] += 1 # Pair each slime's value with its allowed boxes and sort by value descending slimes = sorted(zip(v, s_list), key=lambda x: -x[0]) sums = [0] * m for val, s in slimes: allowed = [] for j in range(m): if s[j] == 'o': allowed.append(j) max_gain = -1 best_j = -1 max_cnt = -1 for j in allowed: current_sum = sums[j] gain = 2 * current_sum * val + val * val if gain > max_gain or (gain == max_gain and count[j] > max_cnt): max_gain = gain best_j = j max_cnt = count[j] sums[best_j] += val total = sum(x ** 2 for x in sums) print(total)