結果

問題 No.2126 MEX Game
ユーザー HIcoderHIcoder
提出日時 2023-07-11 11:44:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,793 bytes
コンパイル時間 1,030 ms
コンパイル使用メモリ 102,052 KB
実行使用メモリ 5,712 KB
最終ジャッジ日時 2023-10-11 03:07:39
合計ジャッジ時間 2,625 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,892 KB
testcase_01 AC 4 ms
4,848 KB
testcase_02 AC 3 ms
4,836 KB
testcase_03 AC 3 ms
4,884 KB
testcase_04 AC 4 ms
5,004 KB
testcase_05 WA -
testcase_06 AC 3 ms
4,952 KB
testcase_07 WA -
testcase_08 AC 4 ms
4,888 KB
testcase_09 AC 4 ms
4,952 KB
testcase_10 AC 29 ms
5,416 KB
testcase_11 AC 29 ms
5,712 KB
testcase_12 AC 29 ms
5,536 KB
testcase_13 AC 29 ms
5,368 KB
testcase_14 AC 30 ms
5,372 KB
testcase_15 AC 30 ms
5,416 KB
testcase_16 AC 30 ms
5,584 KB
testcase_17 AC 24 ms
5,476 KB
testcase_18 AC 25 ms
5,692 KB
testcase_19 AC 17 ms
5,480 KB
testcase_20 AC 17 ms
5,364 KB
testcase_21 AC 30 ms
5,404 KB
testcase_22 AC 3 ms
5,008 KB
testcase_23 AC 4 ms
4,840 KB
testcase_24 AC 4 ms
4,832 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
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;
    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]+cnt2[k]+cntlargerthan2[k]);

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

        }
    }

    cout<<ans<<endl;

}
0