結果

問題 No.1972 Modulo Set
ユーザー harurun
提出日時 2022-06-10 23:02:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 1,513 bytes
コンパイル時間 3,218 ms
コンパイル使用メモリ 191,184 KB
最終ジャッジ日時 2025-01-29 20:13:54
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <string>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <stack>
#include <random>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <assert.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll=long long;
#define read(x) cin>>(x);
#define readll(x) ll (x);cin>>(x);
#define readS(x) string (x);cin>>(x);
#define readvll(x,N) vector<ll> (x)((N));for(int i=0;i<(N);i++){cin>>(x)[i];}
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define rep2d(i,j,H,W) for(ll (i)=0;(i)<(H);(i)++)for(ll (j)=0;(j)<(W);j++)
#define is_in(x,y) (0<=(x) && (x)<H && 0<=(y) && (y)<W)
#define yn {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
inline ll powll(ll x,ll n){ll r=1;while(n>0){if(n&1){r*=x;};x*=x;n>>=1;};return r;}
int main(){
ll N,M;
cin>>N>>M;
readvll(A,N);
ll ans=0;
unordered_map<ll,ll> um;
unordered_set<ll> us;
for(ll i=0;i<N;i++){
A[i]%=M;
um[A[i]]++;
us.insert(A[i]);
if(A[i]){
us.insert(M-A[i]);
}
}
vector<ll> B;
B.reserve(2*N);
for(ll i:us){
if(2*i<=M){
B.push_back(i);
}
}
//sort(B.begin(),B.end());
for(ll i:B){
if(i==0){
ans++;
}else if(2*i==M){
ans++;
}else{
ans+=max(um[i],um[M-i]);
}
}
cout<<ans<<endl;
}
/*
2 4 3 0
*/
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0