結果

問題 No.2126 MEX Game
ユーザー HIcoderHIcoder
提出日時 2023-07-11 11:46:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,801 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 101,936 KB
実行使用メモリ 5,644 KB
最終ジャッジ日時 2023-10-11 03:09:59
合計ジャッジ時間 3,090 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,864 KB
testcase_01 AC 4 ms
4,940 KB
testcase_02 AC 3 ms
4,852 KB
testcase_03 AC 4 ms
4,960 KB
testcase_04 AC 4 ms
5,160 KB
testcase_05 AC 3 ms
4,848 KB
testcase_06 AC 4 ms
4,944 KB
testcase_07 WA -
testcase_08 AC 4 ms
4,952 KB
testcase_09 AC 3 ms
4,800 KB
testcase_10 AC 29 ms
5,488 KB
testcase_11 AC 29 ms
5,368 KB
testcase_12 AC 29 ms
5,644 KB
testcase_13 AC 29 ms
5,420 KB
testcase_14 AC 30 ms
5,324 KB
testcase_15 AC 30 ms
5,412 KB
testcase_16 AC 29 ms
5,380 KB
testcase_17 AC 24 ms
5,348 KB
testcase_18 AC 25 ms
5,344 KB
testcase_19 AC 17 ms
5,604 KB
testcase_20 AC 17 ms
5,420 KB
testcase_21 AC 29 ms
5,368 KB
testcase_22 AC 3 ms
4,956 KB
testcase_23 AC 3 ms
4,960 KB
testcase_24 AC 3 ms
4,816 KB
testcase_25 AC 4 ms
4,904 KB
testcase_26 WA -
testcase_27 AC 3 ms
5,116 KB
testcase_28 AC 4 ms
4,848 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);


int main(){
    int N;
    cin>>N;

    const int MAXN=100000+1;
    vector<int> cnt(100000+10,0);
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<N;i++){
        cnt[A[i]]++;
    }

    vector<int> cnt0(MAXN+1,0),cnt1(MAXN+1,0),cnt2(MAXN+1,0),cntlargerthan2(MAXN+1,0);

    for(int k=0;k<=MAXN;k++){
        if(cnt[k]==0){
            cnt0[k]++;
        }else if(cnt[k]==1){
            cnt1[k]++;
        }else if(cnt[k]==2){
            cnt2[k]++;
        }else if(cnt[k]>2){
            cntlargerthan2[k]++;
        }
    }
    for(int i=1;i<=MAXN;i++){
        cnt0[i]=cnt0[i-1]+cnt0[i];//cnt0[i]=0~iのなかで カウント0の個数
        cnt1[i]=cnt1[i-1]+cnt1[i];
        cnt2[i]=cnt2[i-1]+cnt2[i];
        cntlargerthan2[i]=cntlargerthan2[i-1]+cntlargerthan2[i];

    }

    int ans=0;

   
    for(int k=1;k<=MAXN;k++){
        

        if((cnt2[k-1]+cntlargerthan2[k-1])==k){
            //答えはk以上にできる
            ans=k;
            
        }else if(cnt0[k-1]>0 || cnt1[k-1]>1){
            //答えはk未満
            ans=k-1;
            break;
        }else{
            //[k,MAXN]
            int num=(cnt1[MAXN]+cnt2[MAXN]+cntlargerthan2[MAXN])-(cnt1[k-1]+cnt2[k-1]+cntlargerthan2[k-1]);

            if(cntlargerthan2[k-1]>2 || num>=1){
                ans=k;
            }else{
                ans=k-1;
                break;
            }

        }
    }

    cout<<ans<<endl;

}
0