結果

問題 No.1972 Modulo Set
ユーザー Theta
提出日時 2022-11-07 16:42:53
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 929 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 29,716 KB
最終ジャッジ日時 2024-07-21 00:17:48
合計ジャッジ時間 5,409 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter, defaultdict


def main():
    N, M = map(int, input().split())
    modulo_list = map(lambda num: int(num) % M, input().split())

    modulo_counter = Counter(modulo_list)
    keys = list(modulo_counter.keys())
    keys.sort()

    modulo_counter_default_dict = defaultdict(int)
    modulo_counter_default_dict.update(modulo_counter)

    if modulo_counter_default_dict[0] > 0:
        modulo_counter[0] = 1
    if M % 2 == 0 and modulo_counter_default_dict[M // 2] > 0:
        modulo_counter[M//2] = 1

    for num_key in keys:
        if num_key == 0:
            continue

        if num_key >= (M+1) // 2:
            break

        if modulo_counter_default_dict[num_key] > modulo_counter_default_dict[M-num_key]:
            modulo_counter[M-num_key] = 0
        else:
            modulo_counter[num_key] = 0

    print(sum(modulo_counter.values()))


if __name__ == "__main__":
    main()
0