結果
問題 | No.1972 Modulo Set |
ユーザー |
|
提出日時 | 2022-06-11 04:12:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 171 ms / 2,000 ms |
コード長 | 986 bytes |
コンパイル時間 | 1,692 ms |
コンパイル使用メモリ | 180,488 KB |
実行使用メモリ | 19,072 KB |
最終ジャッジ日時 | 2024-10-05 01:42:30 |
合計ジャッジ時間 | 4,897 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; // aよりもbが大きいならばaをbで更新する // (更新されたならばtrueを返す) template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } // aよりもbが小さいならばaをbで更新する // (更新されたならばtrueを返す) template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } int main(){ ll N,M; cin>>N>>M; set<ll> se; map<ll,ll> ma; for(int i=0;i<N;++i){ ll a; cin>>a; a%=M; ma[a]++; a = min(a,M-a); se.insert(a); } ll ans=0; for(auto a:se){ if(a==0||a*2==M){ ans++; } else{ ans+=max(ma[a],ma[M-a]); } } cout<<ans<<endl; }