結果

問題 No.1972 Modulo Set
ユーザー mnmmnm
提出日時 2022-06-13 21:21:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,445 bytes
コンパイル時間 824 ms
コンパイル使用メモリ 83,924 KB
実行使用メモリ 10,004 KB
最終ジャッジ日時 2024-04-08 17:35:07
合計ジャッジ時間 4,855 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,004 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

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 in(a) cin >> a
#define out(a,b) cout << a << b
using namespace std;
using lint = long long;

lint count_elem_inc(vector<lint> x, lint elem, lint *i){
    lint cnt=0;
    for(; *i<x.size(); ++*i){
        if(x[*i]!=elem)  break;
        cnt++;
    }
    return cnt;
}
lint count_elem_dec(vector<lint> x, lint elem, lint *i){
    lint cnt=0;
    for(; *i>0; --*i){
        if(x[*i]!=elem)  break;
        cnt++;
    }
    return cnt;
}

int main(void){
    lint i, j;
    lint p, n, m;
    in(n); in(m);
    vector<lint> rem(n);
    rep(i,n){
        lint input;
        in(input);
        rem[i]=input%m;
    }
    lint cnt=n;
    sort(rem.begin(),rem.end());
    lint *cur_l, *cur_r;
    lint init_l=0, init_r=n-1;
    cur_l=&init_l; cur_r=&init_r;
    if(rem[*cur_l]==0){
        cnt-=count_elem_inc(rem, 0, cur_l);
        cnt++;
    }
    for(; rem[*cur_l]<m/2+m%2;){
        for(; rem[*cur_r]>m-rem[*cur_l]; --*cur_r);
        lint cur_elem=rem[*cur_l];
        lint l_cnt=count_elem_inc(rem, cur_elem, cur_l);
        lint r_cnt=count_elem_dec(rem, m-cur_elem, cur_r);
        cnt-=min(l_cnt,r_cnt);
    }
    if(m%2==0&&rem[*cur_l]==m/2){
        cnt-=count_elem_inc(rem, m/2, cur_l);
        cnt++;
    }
    if(cnt==0)  cnt=1;
    out(cnt,endl);

    return 0;
}
0