結果

問題 No.1972 Modulo Set
ユーザー simansiman
提出日時 2022-06-11 09:52:01
言語 Ruby
(3.3.0)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 418 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 33,408 KB
最終ジャッジ日時 2024-04-15 08:58:09
合計ジャッジ時間 7,172 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
12,288 KB
testcase_01 AC 92 ms
12,288 KB
testcase_02 AC 90 ms
12,160 KB
testcase_03 AC 104 ms
13,696 KB
testcase_04 AC 110 ms
14,592 KB
testcase_05 AC 115 ms
14,848 KB
testcase_06 AC 123 ms
16,512 KB
testcase_07 AC 142 ms
19,200 KB
testcase_08 AC 115 ms
15,360 KB
testcase_09 AC 94 ms
12,416 KB
testcase_10 AC 111 ms
14,464 KB
testcase_11 AC 146 ms
19,328 KB
testcase_12 AC 101 ms
13,056 KB
testcase_13 AC 100 ms
12,672 KB
testcase_14 AC 100 ms
13,056 KB
testcase_15 AC 153 ms
21,888 KB
testcase_16 AC 164 ms
22,400 KB
testcase_17 AC 114 ms
15,488 KB
testcase_18 AC 90 ms
12,160 KB
testcase_19 AC 152 ms
21,120 KB
testcase_20 AC 168 ms
22,528 KB
testcase_21 AC 117 ms
16,256 KB
testcase_22 AC 140 ms
20,480 KB
testcase_23 AC 222 ms
31,488 KB
testcase_24 AC 135 ms
19,200 KB
testcase_25 AC 161 ms
23,552 KB
testcase_26 AC 172 ms
24,192 KB
testcase_27 AC 222 ms
31,744 KB
testcase_28 AC 133 ms
20,864 KB
testcase_29 AC 161 ms
23,424 KB
testcase_30 AC 203 ms
29,824 KB
testcase_31 AC 95 ms
12,544 KB
testcase_32 AC 187 ms
26,112 KB
testcase_33 AC 261 ms
33,280 KB
testcase_34 AC 246 ms
33,152 KB
testcase_35 AC 237 ms
33,152 KB
testcase_36 AC 243 ms
33,408 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

counter = A.map { |a| a % M }.tally
counter.default = 0

ans = 0
checked = Hash.new(false)

counter.each do |i, cnt|
  j = M - i
  next if checked[j]
  checked[i] = true
  checked[j] = true

  cnt_1 = ((i + i) % M == 0) ? [1, counter[i]].min : counter[i]
  cnt_2 = ((j + j) % M == 0) ? [1, counter[j]].min : counter[j]
  ans += [cnt_1, cnt_2].max
end

puts ans
0