結果

問題 No.1972 Modulo Set
ユーザー milanis48663220milanis48663220
提出日時 2022-06-10 21:29:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,886 bytes
コンパイル時間 1,333 ms
コンパイル使用メモリ 125,260 KB
実行使用メモリ 9,952 KB
最終ジャッジ日時 2023-07-27 22:17:04
合計ジャッジ時間 4,449 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 9 ms
4,376 KB
testcase_04 AC 12 ms
4,380 KB
testcase_05 AC 13 ms
4,376 KB
testcase_06 AC 22 ms
4,380 KB
testcase_07 AC 34 ms
4,380 KB
testcase_08 AC 14 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 13 ms
4,380 KB
testcase_11 AC 33 ms
4,376 KB
testcase_12 AC 7 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 45 ms
5,620 KB
testcase_16 AC 50 ms
6,256 KB
testcase_17 AC 16 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 40 ms
5,908 KB
testcase_20 AC 50 ms
6,512 KB
testcase_21 AC 20 ms
4,380 KB
testcase_22 AC 34 ms
5,616 KB
testcase_23 AC 79 ms
8,852 KB
testcase_24 AC 26 ms
5,384 KB
testcase_25 AC 41 ms
6,608 KB
testcase_26 AC 61 ms
6,280 KB
testcase_27 AC 83 ms
9,072 KB
testcase_28 AC 26 ms
5,420 KB
testcase_29 AC 43 ms
6,576 KB
testcase_30 AC 60 ms
7,864 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 53 ms
7,328 KB
testcase_33 AC 99 ms
9,824 KB
testcase_34 AC 102 ms
9,948 KB
testcase_35 AC 100 ms
9,952 KB
testcase_36 AC 102 ms
9,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; ll m; cin >> n >> m;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    map<ll, int> cnt;
    for(ll x: a){
        ll r = x%m;
        if(cnt.count(r)) cnt[r]++;
        else cnt[r] = 1;
    }
    int ans = 0;
    for(auto [x, c]: cnt){
        if(x+x == m){
            ans++;
            continue;
        }
        if(x == 0){
            ans++;
            continue;
        }
        ll y = m-x;
        if(cnt.count(y) == 0){
            ans += c;
        }else{
            if(x > y) continue;
            ans += max(c, cnt[y]);
        }
    }
    cout << ans << endl;
}
0