結果

問題 No.1972 Modulo Set
ユーザー RuiRui
提出日時 2022-11-18 20:22:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,321 bytes
コンパイル時間 4,067 ms
コンパイル使用メモリ 244,572 KB
実行使用メモリ 15,052 KB
最終ジャッジ日時 2023-10-20 05:29:26
合計ジャッジ時間 7,959 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 15 ms
4,348 KB
testcase_04 AC 21 ms
4,348 KB
testcase_05 AC 24 ms
4,348 KB
testcase_06 AC 37 ms
4,348 KB
testcase_07 AC 57 ms
4,488 KB
testcase_08 AC 25 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 20 ms
4,348 KB
testcase_11 AC 55 ms
4,432 KB
testcase_12 AC 10 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 67 ms
6,580 KB
testcase_16 AC 76 ms
7,804 KB
testcase_17 AC 26 ms
4,964 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 64 ms
7,620 KB
testcase_20 AC 81 ms
8,612 KB
testcase_21 AC 31 ms
5,128 KB
testcase_22 AC 51 ms
7,388 KB
testcase_23 AC 119 ms
13,096 KB
testcase_24 AC 41 ms
7,448 KB
testcase_25 AC 66 ms
9,280 KB
testcase_26 AC 92 ms
7,332 KB
testcase_27 AC 123 ms
13,588 KB
testcase_28 AC 42 ms
7,480 KB
testcase_29 AC 65 ms
9,556 KB
testcase_30 AC 96 ms
11,724 KB
testcase_31 AC 5 ms
4,348 KB
testcase_32 AC 83 ms
11,092 KB
testcase_33 AC 139 ms
15,052 KB
testcase_34 AC 138 ms
15,048 KB
testcase_35 AC 138 ms
15,048 KB
testcase_36 AC 137 ms
15,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

typedef long long ll;
typedef modint998244353 mint;
const int MOD = 1000000007;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1 << 30;
const ll INF = 1LL << 60;
const int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
const int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main(){
    ll n, m;
    cin >> n >> m;

    if(m == 1){
        cout << 1 << endl;
        return 0;
    }

    map<ll, int> mp;
    rep(i, n){
        ll a;
        cin >> a;
        mp[a % m]++;
    }

    vector<pair<int, ll>> vec;
    for(auto it = mp.begin(); it != mp.end(); it++){
        vec.push_back({it->second, it->first});
    }

    sort(all(vec));
    reverse(all(vec));

    int ans = 0;
    set<ll> st;
    rep(i, vec.size()){
        if(vec[i].second == 0) ans++;
        else if(m % 2 == 0 && vec[i].second == m / 2) ans++;
        else if(!st.count(m - vec[i].second)){
            ans += vec[i].first;
            st.insert(vec[i].second);
        }
    }

    cout << ans << endl;

    return 0;
}
0