結果

問題 No.1972 Modulo Set
コンテスト
ユーザー qib
提出日時 2023-04-01 00:55:46
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 466 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 126 ms
コンパイル使用メモリ 84,952 KB
実行使用メモリ 136,104 KB
最終ジャッジ日時 2026-04-11 08:23:42
合計ジャッジ時間 3,239 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n, m = map(int, input().split())
a = list(map(int, input().split()))

if m == 1:
  print("1")
  exit()

cnt = {}
for i in range(n):
  x = a[i] % m
  cnt[x] = cnt.get(x, 0) + 1

ans = 0
used = {}
for x in cnt.keys():
  y = (m - x) % m
  if not used.get(x, None) is None or not used.get(y, None) is None:
    continue

  used[x] = True
  used[y] = True
  if x == y:
    ans += 1
  else:
    ans += max(cnt.get(x, 0), cnt.get(y, 0))

if ans == 0:
  ans += 1

print(ans)
0