結果
問題 | No.2178 Payable Magic Items |
ユーザー |
![]() |
提出日時 | 2025-03-20 20:21:39 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,872 bytes |
コンパイル時間 | 249 ms |
コンパイル使用メモリ | 82,552 KB |
実行使用メモリ | 276,840 KB |
最終ジャッジ日時 | 2025-03-20 20:24:12 |
合計ジャッジ時間 | 57,034 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 TLE * 7 |
ソースコード
import sysimport itertoolsdef main():input = sys.stdin.read().split()idx = 0N, K = int(input[idx]), int(input[idx+1])idx +=2points_input = []for _ in range(N):s = input[idx]digits = tuple(map(int, list(s)))points_input.append(digits)idx += 1# Generate all possible points (K-dimensional)all_points = list(itertools.product(range(5), repeat=K))code_to_idx = {p:i for i, p in enumerate(all_points)}total_points = len(all_points)# Initialize presence and cumsumpresence = [0] * total_pointsfor p in points_input:idx_p = code_to_idx[p]presence[idx_p] = 1cumsum = presence.copy()# Precompute code to index mapping for all pointsfor d in range(K):# Sort all points in decreasing order of current dimension dsorted_points = sorted(all_points, key=lambda x: x[d], reverse=True)# Temporary array to hold new cumsum values for this dimensionnew_cumsum = [0] * total_points# For each point in sorted order (by dimension d)for p in sorted_points:code = code_to_idx[p]current_sum = cumsum[code]current_val = p[d]if current_val < 4:q = list(p)q[d] = current_val + 1q_tuple = tuple(q)q_code = code_to_idx[q_tuple]current_sum += new_cumsum[q_code]new_cumsum[code] = current_sum# Update cumsum after processing dimension dcumsum = new_cumsum# Now check each input pointcount = 0for p in points_input:code = code_to_idx[p]# The sum includes itself, so if sum is >=2, it's sellableif cumsum[code] >= 2:count += 1print(count)if __name__ == '__main__':main()