結果

問題 No.1972 Modulo Set
ユーザー mmn15277198
提出日時 2022-08-04 23:53:41
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 420 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 1,760 ms
コンパイル使用メモリ 177,548 KB
実行使用メモリ 26,624 KB
最終ジャッジ日時 2024-09-14 20:18:51
合計ジャッジ時間 7,693 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long m;
  cin >> n >> m;
  vector<long long> a(n);
  map<long long, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] %= m;
    mp[a[i]]++;
  }
  long long ans = 0;
  bool ok1 = false;
  bool ok2 = false;
  map<long long, int> used;
  for (int i = 0; i < n; i++) {
    if (used[a[i]]) continue;
    if (a[i] * 2 == m) ok1 = true;
    else if (a[i] == 0) ok2 = true;
    else ans += max(mp[a[i]], mp[m - a[i]]);
    used[a[i]]++;
    used[m - a[i]]++;
  }
  ans += ok1 + ok2;
  cout << ans << endl;
  return 0;
}
0