結果
問題 |
No.2178 Payable Magic Items
|
ユーザー |
![]() |
提出日時 | 2025-04-15 23:12:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 755 ms / 4,000 ms |
コード長 | 1,470 bytes |
コンパイル時間 | 532 ms |
コンパイル使用メモリ | 82,632 KB |
実行使用メモリ | 116,496 KB |
最終ジャッジ日時 | 2025-04-15 23:14:49 |
合計ジャッジ時間 | 10,976 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
import sys import itertools def components_to_index(components): index = 0 for c in components: index = index * 5 + c return index def main(): N, K = map(int, sys.stdin.readline().split()) tuples = [] max_index = 5 ** K arr = [0] * max_index for _ in range(N): s = sys.stdin.readline().strip() components = list(map(int, s)) index = components_to_index(components) tuples.append(components) arr[index] = 1 for d in range(K): other_dims = [i for i in range(K) if i != d] ranges = [range(5) for _ in range(K - 1)] for other_values in itertools.product(*ranges): components = [0] * K idx = 0 for i in range(K): if i == d: continue components[i] = other_values[idx] idx += 1 for a_d in range(4, -1, -1): components[d] = a_d index = components_to_index(components) if a_d < 4: next_components = components.copy() next_components[d] += 1 next_index = components_to_index(next_components) arr[index] += arr[next_index] answer = 0 for components in tuples: index = components_to_index(components) if arr[index] >= 2: answer += 1 print(answer) if __name__ == '__main__': main()