結果
| 問題 |
No.1972 Modulo Set
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:25:34 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,216 bytes |
| コンパイル時間 | 167 ms |
| コンパイル使用メモリ | 82,288 KB |
| 実行使用メモリ | 106,948 KB |
| 最終ジャッジ日時 | 2025-03-20 20:26:49 |
| 合計ジャッジ時間 | 4,859 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 WA * 8 |
ソースコード
import sys
from collections import defaultdict
def main():
n, m = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
counter = defaultdict(int)
for num in a:
mod = num % m
counter[mod] += 1
zeros = counter.get(0, 0)
optional_zero = 1 if zeros > 0 else 0
processed = set()
total = 0
# Iterate over a fixed list of keys to avoid runtime error during dictionary changes
for r in list(counter.keys()):
if r == 0:
continue
if r in processed:
continue
s = m - r
if s not in counter:
total += counter[r]
processed.add(r)
else:
if r < s:
if r != s:
total += max(counter[r], counter[s])
processed.add(r)
processed.add(s)
else:
# r == s implies m is even and r = m/2
total += 1
processed.add(r)
# else: do nothing, let the smaller r handle it
answer = total + optional_zero
print(answer)
if __name__ == "__main__":
main()
lam6er