結果

問題 No.1972 Modulo Set
ユーザー mnmmnm
提出日時 2022-06-24 18:57:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,647 bytes
コンパイル時間 1,122 ms
コンパイル使用メモリ 88,508 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-04-26 02:56:38
合計ジャッジ時間 4,296 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 10 ms
5,376 KB
testcase_04 AC 17 ms
5,376 KB
testcase_05 AC 21 ms
5,376 KB
testcase_06 AC 31 ms
5,376 KB
testcase_07 AC 46 ms
5,376 KB
testcase_08 AC 23 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 18 ms
5,376 KB
testcase_11 AC 48 ms
5,376 KB
testcase_12 AC 8 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 44 ms
5,376 KB
testcase_16 AC 43 ms
5,376 KB
testcase_17 AC 16 ms
5,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 29 ms
5,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 55 ms
5,460 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <bitset>

#define rep(i,n) for(i=0; i<n; ++i)
#define inc_rep(i,a,n) for(i=a; i<n; ++i)
#define dec_rep(i,n,a) for(i=n; i>=a; --i)
#define in(a) cin >> a
#define out(a,b) cout << a << b
#define print_vec(v) for(auto it=v.begin();it!=v.end();++it)cout<<*it <<" ";cout<<endl
#define print_vec2d(v) for(int i=0;i<v.size();++i){for(int j=0;j<v[i].size();++j)cout<<v[i][j]<<" ";cout<<endl;}cout<<endl
using namespace std;
using lint = long long;

int main(void){
    lint i, j, k, cnt=0, x, y;
    lint p, n, m;
    in(n); in(m);
    vector<lint> rem(n);
    vector<pair<lint,lint> > cnt_rem;
    rep(i,n){
        lint inp; in(inp);
        rem[i]=inp%m;
    }
    sort(rem.begin(),rem.end());
    i=0;
    while(i<n){
        cnt=0;
        lint temp=rem[i];
        inc_rep(i,i,n){
            if(temp!=rem[i])    break;
            cnt++;
        }
        cnt_rem.push_back(make_pair(temp,cnt));
    }
    cnt=0;
    i=0; j=cnt_rem.size()-1;
    lint elem_i, cnt_i, elem_j, cnt_j;
    while(i<j){
        tie(elem_i, cnt_i)=cnt_rem[i];
        tie(elem_j, cnt_j)=cnt_rem[j];
        if(elem_i==0){
            cnt++;
            i++;
        }
        else if(elem_i+elem_j==m){
            cnt+=max(cnt_i,cnt_j);
            i++; j--;
        }
        else if(elem_i>m-elem_j){
            cnt+=cnt_j;
            j--;
        }
        else if(elem_i<m-elem_j){
            cnt+=cnt_i;
            i++;
        }
    }
    if(m%2==0&&cnt_rem[i].first==m/2)   cnt++;
    if(n==1)    cnt=1;
    out(cnt,endl);
    return 0;
}
0