結果
問題 | No.1972 Modulo Set |
ユーザー |
|
提出日時 | 2024-10-28 21:52:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 245 ms / 2,000 ms |
コード長 | 923 bytes |
コンパイル時間 | 2,620 ms |
コンパイル使用メモリ | 208,400 KB |
最終ジャッジ日時 | 2025-02-25 01:09:33 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;#define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i)#define all(a) (a).begin(), (a).end()int main() {cin.tie(nullptr);ll N, M;cin >> N >> M;vector<ll> A(N);rep(i, 0, N) cin >> A[i];rep(i, 0, N) A[i] %= M;set<ll> s;map<ll, int> m;rep(i, 0, N) {s.insert(A[i]);m[A[i]]++;}ll ans = 0;set<ll> seen;for (ll i : s) {if (seen.count(i)) continue;if (i == 0) {ans++;continue;}if (i * 2 == M) {ans++;continue;}seen.insert(i);if (s.count(M - i)) {ans += max(m[i], m[M - i]);seen.insert(M - i);} else {ans += m[i];}}cout << ans << '\n';}